@flaunch/sdk 0.9.5 → 0.9.7
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 +14 -0
- package/dist/clients/FlaunchZapClient.d.ts +4 -3
- package/dist/clients/FlaunchZapClient.d.ts.map +1 -1
- package/dist/index.cjs.js +260 -107
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +260 -107
- 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 +49 -1
- package/dist/sdk/FlaunchSDK.d.ts.map +1 -1
- package/dist/types.d.ts +5 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/univ4.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -836,6 +836,20 @@ const calls = addLiqCalls.map((call) => ({
|
|
|
836
836
|
await sendCalls({ calls });
|
|
837
837
|
```
|
|
838
838
|
|
|
839
|
+
3. **Single-Sided Coin Liquidity (Current Price to Infinity)**
|
|
840
|
+
|
|
841
|
+
You can easily provide single-sided coin liquidity from the current price to infinity.
|
|
842
|
+
|
|
843
|
+
```ts
|
|
844
|
+
const singleSidedCalls = await flaunchWrite.getSingleSidedCoinAddLiquidityCalls(
|
|
845
|
+
{
|
|
846
|
+
coinAddress: "0x...", // Token contract address
|
|
847
|
+
coinAmount: parseEther("1000000"), // Amount of coins to provide as liquidity
|
|
848
|
+
version: FlaunchVersion.V1_2, // optional (auto-determines if not provided)
|
|
849
|
+
}
|
|
850
|
+
);
|
|
851
|
+
```
|
|
852
|
+
|
|
839
853
|
### Import AND Add Liquidity calls in a single batch
|
|
840
854
|
|
|
841
855
|
1. This allows an external coin to be live on flaunch, and be tradeable instantly with the liquidity being provided in the same transaction batch.
|
|
@@ -43,6 +43,7 @@ export interface FlaunchWithRevenueManagerIPFSParams extends Omit<FlaunchWithRev
|
|
|
43
43
|
}
|
|
44
44
|
export interface FlaunchWithSplitManagerParams extends Omit<FlaunchParams, "treasuryManagerParams"> {
|
|
45
45
|
creatorSplitPercent: number;
|
|
46
|
+
managerOwnerSplitPercent: number;
|
|
46
47
|
splitReceivers: {
|
|
47
48
|
address: Address;
|
|
48
49
|
percent: number;
|
|
@@ -152,12 +153,12 @@ export declare class ReadWriteFlaunchZap extends ReadFlaunchZap {
|
|
|
152
153
|
* @param params.initialMarketCapUSD - Initial market cap in USD
|
|
153
154
|
* @param params.creator - Address of the token creator
|
|
154
155
|
* @param params.creatorFeeAllocationPercent - Percentage of fees allocated to creator (0-100)
|
|
155
|
-
* @param params.creatorSplitPercent -
|
|
156
|
+
* @param params.creatorSplitPercent - Split percentage of the fees for the creator (0-100)
|
|
157
|
+
* @param params.managerOwnerSplitPercent - Split percentage of the fees for the manager owner (0-100)
|
|
156
158
|
* @param params.splitReceivers - List of recipients and their percentage of the fees
|
|
157
159
|
* @param params.flaunchAt - Optional timestamp when the flaunch should start
|
|
158
160
|
* @param params.premineAmount - Optional amount of tokens to premine
|
|
159
|
-
* @param params.
|
|
160
|
-
* @param params.splitReceivers - List of recipients and their percentage of the fees
|
|
161
|
+
* @param params.treasuryManagerParams - Optional treasury manager configuration
|
|
161
162
|
* @returns Transaction response for the flaunch creation
|
|
162
163
|
*/
|
|
163
164
|
flaunchWithSplitManager(params: FlaunchWithSplitManagerParams): Promise<`0x${string}`>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FlaunchZapClient.d.ts","sourceRoot":"","sources":["../../src/clients/FlaunchZapClient.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,OAAO,EACZ,KAAK,KAAK,EAEV,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,SAAS,EAEf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAKlD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM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EAAE,MAAM,CAAC;KAC1B;IAgBK,gBAAgB,CAAC,MAAM,EAAE;QAC7B,MAAM,EAAE,OAAO,CAAC;QAChB,kBAAkB,EAAE,SAAS,CAAC;QAC9B,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B;IAgBD;;OAEG;IACH,oBAAoB,CAAC,MAAM,EAAE;QAC3B,aAAa,EAAE,MAAM,CAAC;QACtB,kBAAkB,EAAE,SAAS,CAAC;QAC9B,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B;CASF;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,cAAc;IAC7C,QAAQ,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAC;gBAGjD,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,KAAK,GAAE,KAAK,CAAC,gBAAgB,CAAiB;IAKhD;;;;OAIG;IACG,OAAO,CAAC,MAAM,EAAE,aAAa;IAkI7B,WAAW,CAAC,MAAM,EAAE,iBAAiB;IAY3C;;;;;;;;;;;;;;;;OAgBG;IACG,yBAAyB,CAAC,MAAM,EAAE,+BAA+B;IAavE;;;;OAIG;IACG,6BAA6B,CACjC,MAAM,EAAE,mCAAmC;IAa7C;;;;;;;;;;;;;;;;;;OAkBG;IACG,uBAAuB,CAAC,MAAM,EAAE,6BAA6B;IAgEnE;;;;OAIG;IACG,2BAA2B,CAAC,MAAM,EAAE,iCAAiC;IAY3E;;;;;;;OAOG;IACH,oBAAoB,CAAC,MAAM,EAAE,0BAA0B;IA8BvD;;;;;;;;;;;OAWG;IACH,oBAAoB,CAAC,MAAM,EAAE,0BAA0B;CA8CxD"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -14006,17 +14006,18 @@ class ReadWriteFlaunchZap extends ReadFlaunchZap {
|
|
|
14006
14006
|
* @param params.initialMarketCapUSD - Initial market cap in USD
|
|
14007
14007
|
* @param params.creator - Address of the token creator
|
|
14008
14008
|
* @param params.creatorFeeAllocationPercent - Percentage of fees allocated to creator (0-100)
|
|
14009
|
-
* @param params.creatorSplitPercent -
|
|
14009
|
+
* @param params.creatorSplitPercent - Split percentage of the fees for the creator (0-100)
|
|
14010
|
+
* @param params.managerOwnerSplitPercent - Split percentage of the fees for the manager owner (0-100)
|
|
14010
14011
|
* @param params.splitReceivers - List of recipients and their percentage of the fees
|
|
14011
14012
|
* @param params.flaunchAt - Optional timestamp when the flaunch should start
|
|
14012
14013
|
* @param params.premineAmount - Optional amount of tokens to premine
|
|
14013
|
-
* @param params.
|
|
14014
|
-
* @param params.splitReceivers - List of recipients and their percentage of the fees
|
|
14014
|
+
* @param params.treasuryManagerParams - Optional treasury manager configuration
|
|
14015
14015
|
* @returns Transaction response for the flaunch creation
|
|
14016
14016
|
*/
|
|
14017
14017
|
async flaunchWithSplitManager(params) {
|
|
14018
14018
|
const VALID_SHARE_TOTAL = 10000000n; // 5 decimals as BigInt
|
|
14019
14019
|
let creatorShare = (BigInt(params.creatorSplitPercent) * VALID_SHARE_TOTAL) / 100n;
|
|
14020
|
+
const managerOwnerShare = (BigInt(params.managerOwnerSplitPercent) * VALID_SHARE_TOTAL) / 100n;
|
|
14020
14021
|
const recipientShares = params.splitReceivers.map((receiver) => {
|
|
14021
14022
|
return {
|
|
14022
14023
|
recipient: receiver.address,
|
|
@@ -14025,7 +14026,7 @@ class ReadWriteFlaunchZap extends ReadFlaunchZap {
|
|
|
14025
14026
|
});
|
|
14026
14027
|
const totalRecipientShares = recipientShares.reduce((acc, curr) => acc + curr.share, 0n);
|
|
14027
14028
|
// if there's a remainder (due to rounding errors), add it to the creator share
|
|
14028
|
-
const remainderShares = VALID_SHARE_TOTAL - totalRecipientShares;
|
|
14029
|
+
const remainderShares = VALID_SHARE_TOTAL - totalRecipientShares - managerOwnerShare;
|
|
14029
14030
|
creatorShare += remainderShares;
|
|
14030
14031
|
const initializeData = viem.encodeAbiParameters([
|
|
14031
14032
|
{
|
|
@@ -14033,6 +14034,7 @@ class ReadWriteFlaunchZap extends ReadFlaunchZap {
|
|
|
14033
14034
|
name: "params",
|
|
14034
14035
|
components: [
|
|
14035
14036
|
{ type: "uint256", name: "creatorShare" },
|
|
14037
|
+
{ type: "uint256", name: "ownerShare" },
|
|
14036
14038
|
{
|
|
14037
14039
|
type: "tuple[]",
|
|
14038
14040
|
name: "recipientShares",
|
|
@@ -14046,6 +14048,7 @@ class ReadWriteFlaunchZap extends ReadFlaunchZap {
|
|
|
14046
14048
|
], [
|
|
14047
14049
|
{
|
|
14048
14050
|
creatorShare,
|
|
14051
|
+
ownerShare: managerOwnerShare,
|
|
14049
14052
|
recipientShares,
|
|
14050
14053
|
},
|
|
14051
14054
|
]);
|
|
@@ -25464,6 +25467,10 @@ function maxLiquidityForAmount0Precise(sqrtRatioAX96, sqrtRatioBX96, amount0) {
|
|
|
25464
25467
|
if (sqrtRatioAX96 > sqrtRatioBX96) {
|
|
25465
25468
|
[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
|
|
25466
25469
|
}
|
|
25470
|
+
// Handle edge case where sqrt ratios are equal (division by zero)
|
|
25471
|
+
if (sqrtRatioAX96 === sqrtRatioBX96) {
|
|
25472
|
+
return 0n;
|
|
25473
|
+
}
|
|
25467
25474
|
const Q96 = 2n ** 96n;
|
|
25468
25475
|
const numerator = amount0 * sqrtRatioAX96 * sqrtRatioBX96;
|
|
25469
25476
|
const denominator = Q96 * (sqrtRatioBX96 - sqrtRatioAX96);
|
|
@@ -25480,6 +25487,10 @@ function maxLiquidityForAmount1(sqrtRatioAX96, sqrtRatioBX96, amount1) {
|
|
|
25480
25487
|
if (sqrtRatioAX96 > sqrtRatioBX96) {
|
|
25481
25488
|
[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
|
|
25482
25489
|
}
|
|
25490
|
+
// Handle edge case where sqrt ratios are equal (division by zero)
|
|
25491
|
+
if (sqrtRatioAX96 === sqrtRatioBX96) {
|
|
25492
|
+
return 0n;
|
|
25493
|
+
}
|
|
25483
25494
|
const Q96 = 2n ** 96n;
|
|
25484
25495
|
return (amount1 * Q96) / (sqrtRatioBX96 - sqrtRatioAX96);
|
|
25485
25496
|
}
|
|
@@ -26391,7 +26402,7 @@ class ReadFlaunchSDK {
|
|
|
26391
26402
|
* @returns Promise<number> - The current tick of the pool
|
|
26392
26403
|
*/
|
|
26393
26404
|
async currentTick(coinAddress, version) {
|
|
26394
|
-
const coinVersion =
|
|
26405
|
+
const coinVersion = await this.determineCoinVersion(coinAddress, version);
|
|
26395
26406
|
const poolId = await this.poolId(coinAddress, coinVersion);
|
|
26396
26407
|
const poolState = await this.readStateView.poolSlot0({ poolId });
|
|
26397
26408
|
return poolState.tick;
|
|
@@ -26403,7 +26414,7 @@ class ReadFlaunchSDK {
|
|
|
26403
26414
|
* @returns Promise<string> - The price of the coin in ETH with 18 decimals precision
|
|
26404
26415
|
*/
|
|
26405
26416
|
async coinPriceInETH(coinAddress, version) {
|
|
26406
|
-
const coinVersion =
|
|
26417
|
+
const coinVersion = await this.determineCoinVersion(coinAddress, version);
|
|
26407
26418
|
const isFLETHZero = this.flETHIsCurrencyZero(coinAddress);
|
|
26408
26419
|
const currentTick = await this.currentTick(coinAddress, coinVersion);
|
|
26409
26420
|
const price = Math.pow(1.0001, currentTick);
|
|
@@ -26423,7 +26434,7 @@ class ReadFlaunchSDK {
|
|
|
26423
26434
|
* @returns Promise<string> - The price of the coin in USD with 18 decimal precision
|
|
26424
26435
|
*/
|
|
26425
26436
|
async coinPriceInUSD({ coinAddress, version, drift, }) {
|
|
26426
|
-
const coinVersion =
|
|
26437
|
+
const coinVersion = await this.determineCoinVersion(coinAddress, version);
|
|
26427
26438
|
const ethPerCoin = await this.coinPriceInETH(coinAddress, coinVersion);
|
|
26428
26439
|
const ethPrice = await this.getETHUSDCPrice(drift);
|
|
26429
26440
|
return (parseFloat(ethPerCoin) * ethPrice).toFixed(18);
|
|
@@ -26471,7 +26482,7 @@ class ReadFlaunchSDK {
|
|
|
26471
26482
|
* @returns Fair launch information from the appropriate contract version
|
|
26472
26483
|
*/
|
|
26473
26484
|
async fairLaunchInfo(coinAddress, version) {
|
|
26474
|
-
const coinVersion =
|
|
26485
|
+
const coinVersion = await this.determineCoinVersion(coinAddress, version);
|
|
26475
26486
|
const poolId = await this.poolId(coinAddress, coinVersion);
|
|
26476
26487
|
return this.getFairLaunch(coinVersion).fairLaunchInfo({ poolId });
|
|
26477
26488
|
}
|
|
@@ -26482,12 +26493,12 @@ class ReadFlaunchSDK {
|
|
|
26482
26493
|
* @returns Promise<boolean> - True if fair launch is active, false otherwise
|
|
26483
26494
|
*/
|
|
26484
26495
|
async isFairLaunchActive(coinAddress, version) {
|
|
26485
|
-
const coinVersion =
|
|
26496
|
+
const coinVersion = await this.determineCoinVersion(coinAddress, version);
|
|
26486
26497
|
const poolId = await this.poolId(coinAddress, coinVersion);
|
|
26487
26498
|
return this.getFairLaunch(coinVersion).isFairLaunchActive({ poolId });
|
|
26488
26499
|
}
|
|
26489
26500
|
async trustedPoolKeySignerStatus(coinAddress, version) {
|
|
26490
|
-
const coinVersion =
|
|
26501
|
+
const coinVersion = await this.determineCoinVersion(coinAddress, version);
|
|
26491
26502
|
if (coinVersion === exports.FlaunchVersion.ANY) {
|
|
26492
26503
|
throw new Error("AnyPositionManager is not supported for TrustedSigner");
|
|
26493
26504
|
}
|
|
@@ -26536,7 +26547,7 @@ class ReadFlaunchSDK {
|
|
|
26536
26547
|
* @returns Promise<number> - The duration in seconds (30 minutes for V1, variable for V1.1)
|
|
26537
26548
|
*/
|
|
26538
26549
|
async fairLaunchDuration(coinAddress, version) {
|
|
26539
|
-
const coinVersion =
|
|
26550
|
+
const coinVersion = await this.determineCoinVersion(coinAddress, version);
|
|
26540
26551
|
const poolId = await this.poolId(coinAddress, coinVersion);
|
|
26541
26552
|
return this.getFairLaunch(coinVersion).fairLaunchDuration({ poolId });
|
|
26542
26553
|
}
|
|
@@ -26547,7 +26558,7 @@ class ReadFlaunchSDK {
|
|
|
26547
26558
|
* @returns Promise<number> - The initial tick value
|
|
26548
26559
|
*/
|
|
26549
26560
|
async initialTick(coinAddress, version) {
|
|
26550
|
-
const coinVersion =
|
|
26561
|
+
const coinVersion = await this.determineCoinVersion(coinAddress, version);
|
|
26551
26562
|
const poolId = await this.poolId(coinAddress, coinVersion);
|
|
26552
26563
|
const fairLaunchInfo = await this.getFairLaunch(coinVersion).fairLaunchInfo({ poolId });
|
|
26553
26564
|
return fairLaunchInfo.initialTick;
|
|
@@ -26559,7 +26570,7 @@ class ReadFlaunchSDK {
|
|
|
26559
26570
|
* @returns Promise<{flETHAmount: bigint, coinAmount: bigint, tickLower: number, tickUpper: number}> - Position details
|
|
26560
26571
|
*/
|
|
26561
26572
|
async fairLaunchETHOnlyPosition(coinAddress, version) {
|
|
26562
|
-
const coinVersion =
|
|
26573
|
+
const coinVersion = await this.determineCoinVersion(coinAddress, version);
|
|
26563
26574
|
const poolId = await this.poolId(coinAddress, coinVersion);
|
|
26564
26575
|
const initialTick = await this.initialTick(coinAddress, coinVersion);
|
|
26565
26576
|
const currentTick = await this.currentTick(coinAddress, coinVersion);
|
|
@@ -26607,7 +26618,7 @@ class ReadFlaunchSDK {
|
|
|
26607
26618
|
* @returns Promise<{flETHAmount: bigint, coinAmount: bigint, tickLower: number, tickUpper: number}> - Position details
|
|
26608
26619
|
*/
|
|
26609
26620
|
async fairLaunchCoinOnlyPosition(coinAddress, version) {
|
|
26610
|
-
const coinVersion =
|
|
26621
|
+
const coinVersion = await this.determineCoinVersion(coinAddress, version);
|
|
26611
26622
|
const poolId = await this.poolId(coinAddress, coinVersion);
|
|
26612
26623
|
const initialTick = await this.initialTick(coinAddress, coinVersion);
|
|
26613
26624
|
const currentTick = await this.currentTick(coinAddress, coinVersion);
|
|
@@ -26655,7 +26666,7 @@ class ReadFlaunchSDK {
|
|
|
26655
26666
|
* @returns Promise<{flETHAmount: bigint, coinAmount: bigint, pendingEth: bigint, tickLower: number, tickUpper: number}> - Bid wall position details
|
|
26656
26667
|
*/
|
|
26657
26668
|
async bidWallPosition(coinAddress, version) {
|
|
26658
|
-
const coinVersion =
|
|
26669
|
+
const coinVersion = await this.determineCoinVersion(coinAddress, version);
|
|
26659
26670
|
const poolId = await this.poolId(coinAddress, coinVersion);
|
|
26660
26671
|
const isFLETHZero = this.flETHIsCurrencyZero(coinAddress);
|
|
26661
26672
|
const { amount0_: amount0, amount1_: amount1, pendingEth_: pendingEth, } = await this.getBidWall(coinVersion).position({ poolId });
|
|
@@ -26771,13 +26782,8 @@ class ReadFlaunchSDK {
|
|
|
26771
26782
|
*/
|
|
26772
26783
|
async poolId(coinAddress, version) {
|
|
26773
26784
|
let hookAddress;
|
|
26774
|
-
|
|
26775
|
-
|
|
26776
|
-
}
|
|
26777
|
-
else {
|
|
26778
|
-
const coinVersion = await this.getCoinVersion(coinAddress);
|
|
26779
|
-
hookAddress = this.getPositionManagerAddress(coinVersion);
|
|
26780
|
-
}
|
|
26785
|
+
const coinVersion = await this.determineCoinVersion(coinAddress, version);
|
|
26786
|
+
hookAddress = this.getPositionManagerAddress(coinVersion);
|
|
26781
26787
|
return getPoolId(orderPoolKey({
|
|
26782
26788
|
currency0: FLETHAddress[this.chainId],
|
|
26783
26789
|
currency1: coinAddress,
|
|
@@ -26835,7 +26841,7 @@ class ReadFlaunchSDK {
|
|
|
26835
26841
|
* @returns Promise<bigint> - The expected amount of ETH to receive
|
|
26836
26842
|
*/
|
|
26837
26843
|
async getSellQuoteExactInput({ coinAddress, version, amountIn, intermediatePoolKey, }) {
|
|
26838
|
-
const coinVersion =
|
|
26844
|
+
const coinVersion = await this.determineCoinVersion(coinAddress, version);
|
|
26839
26845
|
return this.readQuoter.getSellQuoteExactInput({
|
|
26840
26846
|
coinAddress,
|
|
26841
26847
|
amountIn,
|
|
@@ -26854,7 +26860,7 @@ class ReadFlaunchSDK {
|
|
|
26854
26860
|
* @returns Promise<bigint> - The expected amount of coins to receive
|
|
26855
26861
|
*/
|
|
26856
26862
|
async getBuyQuoteExactInput({ coinAddress, version, amountIn, intermediatePoolKey, hookData, userWallet, }) {
|
|
26857
|
-
const coinVersion =
|
|
26863
|
+
const coinVersion = await this.determineCoinVersion(coinAddress, version);
|
|
26858
26864
|
return this.readQuoter.getBuyQuoteExactInput({
|
|
26859
26865
|
coinAddress,
|
|
26860
26866
|
amountIn,
|
|
@@ -26875,7 +26881,7 @@ class ReadFlaunchSDK {
|
|
|
26875
26881
|
* @returns Promise<bigint> - The required amount of ETH or inputToken to spend
|
|
26876
26882
|
*/
|
|
26877
26883
|
async getBuyQuoteExactOutput({ coinAddress, amountOut, version, intermediatePoolKey, hookData, userWallet, }) {
|
|
26878
|
-
const coinVersion =
|
|
26884
|
+
const coinVersion = await this.determineCoinVersion(coinAddress, version);
|
|
26879
26885
|
return this.readQuoter.getBuyQuoteExactOutput({
|
|
26880
26886
|
coinAddress,
|
|
26881
26887
|
coinOut: amountOut,
|
|
@@ -27062,24 +27068,9 @@ class ReadFlaunchSDK {
|
|
|
27062
27068
|
});
|
|
27063
27069
|
// If no current tick is provided from the above calculation, get it from the pool state
|
|
27064
27070
|
if (!currentTick) {
|
|
27065
|
-
|
|
27066
|
-
// if version is not provided, check on existing managers, else default to ANY
|
|
27067
|
-
if (!version) {
|
|
27068
|
-
try {
|
|
27069
|
-
version = await this.getCoinVersion(coinAddress);
|
|
27070
|
-
}
|
|
27071
|
-
catch {
|
|
27072
|
-
version = exports.FlaunchVersion.ANY;
|
|
27073
|
-
}
|
|
27074
|
-
}
|
|
27071
|
+
const version = await this.determineCoinVersion(coinAddress, params.version);
|
|
27075
27072
|
const poolState = await this.readStateView.poolSlot0({
|
|
27076
|
-
poolId: getPoolId(
|
|
27077
|
-
currency0: coinAddress,
|
|
27078
|
-
currency1: FLETHAddress[this.chainId],
|
|
27079
|
-
fee: 0,
|
|
27080
|
-
tickSpacing: TICK_SPACING,
|
|
27081
|
-
hooks: this.getPositionManagerAddress(version),
|
|
27082
|
-
})),
|
|
27073
|
+
poolId: getPoolId(this.createPoolKey(coinAddress, version)),
|
|
27083
27074
|
});
|
|
27084
27075
|
currentTick = poolState.tick;
|
|
27085
27076
|
}
|
|
@@ -27153,24 +27144,9 @@ class ReadFlaunchSDK {
|
|
|
27153
27144
|
});
|
|
27154
27145
|
// get the current pool state for the coin
|
|
27155
27146
|
if (!currentTick) {
|
|
27156
|
-
|
|
27157
|
-
// if version is not provided, check on existing managers, else default to ANY
|
|
27158
|
-
if (!version) {
|
|
27159
|
-
try {
|
|
27160
|
-
version = await this.getCoinVersion(coinAddress);
|
|
27161
|
-
}
|
|
27162
|
-
catch {
|
|
27163
|
-
version = exports.FlaunchVersion.ANY;
|
|
27164
|
-
}
|
|
27165
|
-
}
|
|
27147
|
+
const version = await this.determineCoinVersion(coinAddress, params.version);
|
|
27166
27148
|
const poolState = await this.readStateView.poolSlot0({
|
|
27167
|
-
poolId: getPoolId(
|
|
27168
|
-
currency0: coinAddress,
|
|
27169
|
-
currency1: FLETHAddress[this.chainId],
|
|
27170
|
-
fee: 0,
|
|
27171
|
-
tickSpacing: TICK_SPACING,
|
|
27172
|
-
hooks: this.getPositionManagerAddress(version),
|
|
27173
|
-
})),
|
|
27149
|
+
poolId: getPoolId(this.createPoolKey(coinAddress, version)),
|
|
27174
27150
|
});
|
|
27175
27151
|
currentTick = poolState.tick;
|
|
27176
27152
|
}
|
|
@@ -27325,6 +27301,39 @@ class ReadFlaunchSDK {
|
|
|
27325
27301
|
args: { owner, operator },
|
|
27326
27302
|
});
|
|
27327
27303
|
}
|
|
27304
|
+
/**
|
|
27305
|
+
* Determines the version for a coin, using provided version or fetching it
|
|
27306
|
+
* @param coinAddress - The coin address
|
|
27307
|
+
* @param version - Optional version, if not provided will be fetched
|
|
27308
|
+
* @returns The determined version
|
|
27309
|
+
*/
|
|
27310
|
+
async determineCoinVersion(coinAddress, version) {
|
|
27311
|
+
if (!version) {
|
|
27312
|
+
try {
|
|
27313
|
+
version = await this.getCoinVersion(coinAddress);
|
|
27314
|
+
}
|
|
27315
|
+
catch {
|
|
27316
|
+
version = exports.FlaunchVersion.ANY;
|
|
27317
|
+
}
|
|
27318
|
+
}
|
|
27319
|
+
return version;
|
|
27320
|
+
}
|
|
27321
|
+
/**
|
|
27322
|
+
* Creates a pool key for the given coin and version
|
|
27323
|
+
* @param coinAddress - The coin address
|
|
27324
|
+
* @param version - The version to use for position manager
|
|
27325
|
+
* @returns The ordered pool key
|
|
27326
|
+
*/
|
|
27327
|
+
createPoolKey(coinAddress, version) {
|
|
27328
|
+
const flethAddress = FLETHAddress[this.chainId];
|
|
27329
|
+
return orderPoolKey({
|
|
27330
|
+
currency0: coinAddress,
|
|
27331
|
+
currency1: flethAddress,
|
|
27332
|
+
fee: 0,
|
|
27333
|
+
tickSpacing: this.TICK_SPACING,
|
|
27334
|
+
hooks: this.getPositionManagerAddress(version),
|
|
27335
|
+
});
|
|
27336
|
+
}
|
|
27328
27337
|
}
|
|
27329
27338
|
class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
|
|
27330
27339
|
constructor(chainId, drift$1 = drift.createDrift(), publicClient) {
|
|
@@ -27449,7 +27458,7 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
|
|
|
27449
27458
|
* @returns Transaction response for the buy operation
|
|
27450
27459
|
*/
|
|
27451
27460
|
async buyCoin(params, version) {
|
|
27452
|
-
const coinVersion =
|
|
27461
|
+
const coinVersion = await this.determineCoinVersion(params.coinAddress, version);
|
|
27453
27462
|
const sender = await this.drift.getSignerAddress();
|
|
27454
27463
|
let amountIn;
|
|
27455
27464
|
let amountOutMin;
|
|
@@ -27534,7 +27543,7 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
|
|
|
27534
27543
|
* @returns Transaction response for the sell operation
|
|
27535
27544
|
*/
|
|
27536
27545
|
async sellCoin(params, version) {
|
|
27537
|
-
const coinVersion =
|
|
27546
|
+
const coinVersion = await this.determineCoinVersion(params.coinAddress, version);
|
|
27538
27547
|
let amountOutMin;
|
|
27539
27548
|
await this.readQuoter.contract.cache.clear();
|
|
27540
27549
|
if (params.amountOutMin === undefined) {
|
|
@@ -27757,22 +27766,8 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
|
|
|
27757
27766
|
let tickLower;
|
|
27758
27767
|
let tickUpper;
|
|
27759
27768
|
let currentTick;
|
|
27760
|
-
|
|
27761
|
-
|
|
27762
|
-
try {
|
|
27763
|
-
version = await this.getCoinVersion(coinAddress);
|
|
27764
|
-
}
|
|
27765
|
-
catch {
|
|
27766
|
-
version = exports.FlaunchVersion.ANY;
|
|
27767
|
-
}
|
|
27768
|
-
}
|
|
27769
|
-
const poolKey = orderPoolKey({
|
|
27770
|
-
currency0: coinAddress,
|
|
27771
|
-
currency1: flethAddress,
|
|
27772
|
-
fee: 0,
|
|
27773
|
-
tickSpacing: this.TICK_SPACING,
|
|
27774
|
-
hooks: this.getPositionManagerAddress(version),
|
|
27775
|
-
});
|
|
27769
|
+
const version = await this.determineCoinVersion(coinAddress, params.version);
|
|
27770
|
+
const poolKey = this.createPoolKey(coinAddress, version);
|
|
27776
27771
|
// Check if we need to calculate values or use direct values
|
|
27777
27772
|
if ("tickLower" in params) {
|
|
27778
27773
|
// Use the directly provided values
|
|
@@ -27970,6 +27965,173 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
|
|
|
27970
27965
|
// Determine amounts for each currency based on pool key ordering
|
|
27971
27966
|
const amount0 = poolKey.currency0 === coinAddress ? coinAmount : flethAmount;
|
|
27972
27967
|
const amount1 = poolKey.currency0 === coinAddress ? flethAmount : coinAmount;
|
|
27968
|
+
// Calculate and constrain liquidity using shared method
|
|
27969
|
+
const { finalLiquidity, finalAmount0, finalAmount1 } = this.calculateConstrainedLiquidity(currentTick, tickLower, tickUpper, amount0, amount1);
|
|
27970
|
+
// 6. Add liquidity
|
|
27971
|
+
calls.push(this.createLiquidityCall(poolKey, tickLower, tickUpper, finalLiquidity, finalAmount0, finalAmount1, userAddress));
|
|
27972
|
+
return calls;
|
|
27973
|
+
}
|
|
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
|
+
*/
|
|
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
|
+
});
|
|
27986
|
+
const addLiquidityCalls = await this.getAddLiquidityCalls({
|
|
27987
|
+
...params,
|
|
27988
|
+
version: exports.FlaunchVersion.ANY, // optimize to avoid fetching if not passed
|
|
27989
|
+
});
|
|
27990
|
+
return [
|
|
27991
|
+
{
|
|
27992
|
+
to: this.readWriteTokenImporter.contract.address,
|
|
27993
|
+
data: this.readWriteTokenImporter.contract.encodeFunctionData("initialize", importParams),
|
|
27994
|
+
description: "Import Memecoin to Flaunch",
|
|
27995
|
+
},
|
|
27996
|
+
...addLiquidityCalls,
|
|
27997
|
+
];
|
|
27998
|
+
}
|
|
27999
|
+
/**
|
|
28000
|
+
* Gets the calls needed to add single-sided liquidity in coin from current tick to infinity
|
|
28001
|
+
* @param params - Parameters for adding single-sided liquidity
|
|
28002
|
+
* @returns Array of calls with descriptions
|
|
28003
|
+
*/
|
|
28004
|
+
async getSingleSidedCoinAddLiquidityCalls(params) {
|
|
28005
|
+
const { coinAddress, coinAmount } = params;
|
|
28006
|
+
const version = await this.determineCoinVersion(coinAddress, params.version);
|
|
28007
|
+
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;
|
|
28013
|
+
// We want to add liquidity from current price to infinity (as coin appreciates vs flETH)
|
|
28014
|
+
// This means providing single-sided coin liquidity that becomes active as coin price increases
|
|
28015
|
+
const isFLETHZero = this.flETHIsCurrencyZero(coinAddress);
|
|
28016
|
+
let tickLower;
|
|
28017
|
+
let tickUpper;
|
|
28018
|
+
if (isFLETHZero) {
|
|
28019
|
+
// flETH is currency0, coin is currency1
|
|
28020
|
+
// Price = coin/flETH. As coin appreciates, price and tick increase.
|
|
28021
|
+
// For single-sided coin position, we need the range to end at current tick
|
|
28022
|
+
// so as price increases beyond current, position becomes coin-only
|
|
28023
|
+
tickLower = TickFinder.MIN_TICK;
|
|
28024
|
+
tickUpper = getValidTick({
|
|
28025
|
+
tick: currentTick,
|
|
28026
|
+
tickSpacing: this.TICK_SPACING,
|
|
28027
|
+
roundDown: true,
|
|
28028
|
+
});
|
|
28029
|
+
}
|
|
28030
|
+
else {
|
|
28031
|
+
// coin is currency0, flETH is currency1
|
|
28032
|
+
// Price = flETH/coin. As coin appreciates, price decreases and tick decreases.
|
|
28033
|
+
// For single-sided coin position, we need the range to start at current tick
|
|
28034
|
+
// so as price decreases below current, position becomes coin-only
|
|
28035
|
+
tickLower = getValidTick({
|
|
28036
|
+
tick: currentTick,
|
|
28037
|
+
tickSpacing: this.TICK_SPACING,
|
|
28038
|
+
roundDown: false,
|
|
28039
|
+
});
|
|
28040
|
+
tickUpper = TickFinder.MAX_TICK;
|
|
28041
|
+
}
|
|
28042
|
+
// Fetch approvals via multicall
|
|
28043
|
+
const userAddress = await this.drift.getSignerAddress();
|
|
28044
|
+
const permit2Address = Permit2Address[this.chainId];
|
|
28045
|
+
const results = await this.drift.multicall({
|
|
28046
|
+
calls: [
|
|
28047
|
+
// coin -> permit2
|
|
28048
|
+
{
|
|
28049
|
+
address: coinAddress,
|
|
28050
|
+
abi: viem.erc20Abi,
|
|
28051
|
+
fn: "allowance",
|
|
28052
|
+
args: {
|
|
28053
|
+
owner: userAddress,
|
|
28054
|
+
spender: permit2Address,
|
|
28055
|
+
},
|
|
28056
|
+
},
|
|
28057
|
+
// coin --permit2--> uni position manager
|
|
28058
|
+
{
|
|
28059
|
+
address: permit2Address,
|
|
28060
|
+
abi: Permit2Abi,
|
|
28061
|
+
fn: "allowance",
|
|
28062
|
+
args: {
|
|
28063
|
+
0: userAddress,
|
|
28064
|
+
1: coinAddress,
|
|
28065
|
+
2: UniV4PositionManagerAddress[this.chainId],
|
|
28066
|
+
},
|
|
28067
|
+
},
|
|
28068
|
+
// coin symbol
|
|
28069
|
+
{
|
|
28070
|
+
address: coinAddress,
|
|
28071
|
+
abi: viem.erc20Abi,
|
|
28072
|
+
fn: "symbol",
|
|
28073
|
+
},
|
|
28074
|
+
],
|
|
28075
|
+
});
|
|
28076
|
+
const coinToPermit2 = results[0].value;
|
|
28077
|
+
const permit2ToUniPosManagerCoinAllowance = results[1].value;
|
|
28078
|
+
const coinSymbol = results[2].value;
|
|
28079
|
+
const needsCoinApproval = coinToPermit2 < coinAmount;
|
|
28080
|
+
const currentTime = Math.floor(Date.now() / 1000);
|
|
28081
|
+
const needsCoinPermit2Approval = permit2ToUniPosManagerCoinAllowance.amount < coinAmount ||
|
|
28082
|
+
permit2ToUniPosManagerCoinAllowance.expiration <= currentTime;
|
|
28083
|
+
const calls = [];
|
|
28084
|
+
// 1. Coin approval to Permit2
|
|
28085
|
+
if (needsCoinApproval) {
|
|
28086
|
+
calls.push({
|
|
28087
|
+
to: coinAddress,
|
|
28088
|
+
description: `Approve ${coinSymbol} for Permit2`,
|
|
28089
|
+
data: viem.encodeFunctionData({
|
|
28090
|
+
abi: viem.erc20Abi,
|
|
28091
|
+
functionName: "approve",
|
|
28092
|
+
args: [permit2Address, coinAmount],
|
|
28093
|
+
}),
|
|
28094
|
+
});
|
|
28095
|
+
}
|
|
28096
|
+
// 2. Permit2 approval for coin to uni position manager
|
|
28097
|
+
const expiration = Math.floor(Date.now() / 1000) + 3600; // 1 hour from now
|
|
28098
|
+
if (needsCoinPermit2Approval) {
|
|
28099
|
+
calls.push({
|
|
28100
|
+
to: permit2Address,
|
|
28101
|
+
description: `Permit2 approval for ${coinSymbol} to UniV4PositionManager`,
|
|
28102
|
+
data: viem.encodeFunctionData({
|
|
28103
|
+
abi: Permit2Abi,
|
|
28104
|
+
functionName: "approve",
|
|
28105
|
+
args: [
|
|
28106
|
+
coinAddress,
|
|
28107
|
+
UniV4PositionManagerAddress[this.chainId],
|
|
28108
|
+
coinAmount,
|
|
28109
|
+
expiration,
|
|
28110
|
+
],
|
|
28111
|
+
}),
|
|
28112
|
+
});
|
|
28113
|
+
}
|
|
28114
|
+
// === generate add liquidity call ===
|
|
28115
|
+
// Determine amounts for each currency based on pool key ordering
|
|
28116
|
+
const flethAmount = 0n;
|
|
28117
|
+
const amount0 = poolKey.currency0 === coinAddress ? coinAmount : flethAmount;
|
|
28118
|
+
const amount1 = poolKey.currency0 === coinAddress ? flethAmount : coinAmount;
|
|
28119
|
+
// Calculate and constrain liquidity using shared method
|
|
28120
|
+
const { finalLiquidity, finalAmount0, finalAmount1 } = this.calculateConstrainedLiquidity(currentTick, tickLower, tickUpper, amount0, amount1);
|
|
28121
|
+
// 3. Add liquidity
|
|
28122
|
+
calls.push(this.createLiquidityCall(poolKey, tickLower, tickUpper, finalLiquidity, finalAmount0, finalAmount1, userAddress));
|
|
28123
|
+
return calls;
|
|
28124
|
+
}
|
|
28125
|
+
/**
|
|
28126
|
+
* Calculates and constrains liquidity amounts for a position
|
|
28127
|
+
* @param currentTick - Current pool tick
|
|
28128
|
+
* @param tickLower - Lower tick of the position
|
|
28129
|
+
* @param tickUpper - Upper tick of the position
|
|
28130
|
+
* @param amount0 - Amount of currency0
|
|
28131
|
+
* @param amount1 - Amount of currency1
|
|
28132
|
+
* @returns Final liquidity and amounts
|
|
28133
|
+
*/
|
|
28134
|
+
calculateConstrainedLiquidity(currentTick, tickLower, tickUpper, amount0, amount1) {
|
|
27973
28135
|
// Calculate liquidity first using user's input amounts
|
|
27974
28136
|
const initialLiquidity = getLiquidityFromAmounts({
|
|
27975
28137
|
currentTick,
|
|
@@ -28035,7 +28197,25 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
|
|
|
28035
28197
|
}
|
|
28036
28198
|
finalAmount0 = amount0; // Use user's full amount as maximum
|
|
28037
28199
|
finalAmount1 = amount1; // Use user's full amount as maximum
|
|
28038
|
-
|
|
28200
|
+
return {
|
|
28201
|
+
finalLiquidity,
|
|
28202
|
+
finalAmount0,
|
|
28203
|
+
finalAmount1,
|
|
28204
|
+
};
|
|
28205
|
+
}
|
|
28206
|
+
/**
|
|
28207
|
+
* Creates the UniV4 Position Manager liquidity call
|
|
28208
|
+
* @param poolKey - The pool key
|
|
28209
|
+
* @param tickLower - Lower tick of the position
|
|
28210
|
+
* @param tickUpper - Upper tick of the position
|
|
28211
|
+
* @param finalLiquidity - Final liquidity amount
|
|
28212
|
+
* @param finalAmount0 - Final amount of currency0
|
|
28213
|
+
* @param finalAmount1 - Final amount of currency1
|
|
28214
|
+
* @param userAddress - User's address
|
|
28215
|
+
* @returns CallWithDescription for adding liquidity
|
|
28216
|
+
*/
|
|
28217
|
+
createLiquidityCall(poolKey, tickLower, tickUpper, finalLiquidity, finalAmount0, finalAmount1, userAddress) {
|
|
28218
|
+
// Prepare mint position parameters
|
|
28039
28219
|
const V4PMActions = {
|
|
28040
28220
|
MINT_POSITION: "02",
|
|
28041
28221
|
SETTLE_PAIR: "0d",
|
|
@@ -28089,8 +28269,7 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
|
|
|
28089
28269
|
currency1: poolKey.currency1,
|
|
28090
28270
|
},
|
|
28091
28271
|
]);
|
|
28092
|
-
|
|
28093
|
-
calls.push({
|
|
28272
|
+
return {
|
|
28094
28273
|
to: UniV4PositionManagerAddress[this.chainId],
|
|
28095
28274
|
data: viem.encodeFunctionData({
|
|
28096
28275
|
abi: [
|
|
@@ -28116,33 +28295,7 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
|
|
|
28116
28295
|
}),
|
|
28117
28296
|
value: 0n,
|
|
28118
28297
|
description: "Add Liquidity",
|
|
28119
|
-
}
|
|
28120
|
-
return calls;
|
|
28121
|
-
}
|
|
28122
|
-
/**
|
|
28123
|
-
* Gets the calls needed to import a memecoin to Flaunch and add liquidity to AnyPositionManager as a batch
|
|
28124
|
-
* @param params - Parameters for importing and adding liquidity
|
|
28125
|
-
* @returns Array of calls with descriptions
|
|
28126
|
-
*/
|
|
28127
|
-
async getImportAndAddLiquidityCalls(params) {
|
|
28128
|
-
const importParams = await this.readWriteTokenImporter.getInitializeParams({
|
|
28129
|
-
coinAddress: params.coinAddress,
|
|
28130
|
-
creatorFeeAllocationPercent: params.creatorFeeAllocationPercent,
|
|
28131
|
-
initialMarketCapUSD: params.initialMarketCapUSD,
|
|
28132
|
-
verifier: params.verifier,
|
|
28133
|
-
});
|
|
28134
|
-
const addLiquidityCalls = await this.getAddLiquidityCalls({
|
|
28135
|
-
...params,
|
|
28136
|
-
version: exports.FlaunchVersion.ANY, // optimize to avoid fetching if not passed
|
|
28137
|
-
});
|
|
28138
|
-
return [
|
|
28139
|
-
{
|
|
28140
|
-
to: this.readWriteTokenImporter.contract.address,
|
|
28141
|
-
data: this.readWriteTokenImporter.contract.encodeFunctionData("initialize", importParams),
|
|
28142
|
-
description: "Import Memecoin to Flaunch",
|
|
28143
|
-
},
|
|
28144
|
-
...addLiquidityCalls,
|
|
28145
|
-
];
|
|
28298
|
+
};
|
|
28146
28299
|
}
|
|
28147
28300
|
}
|
|
28148
28301
|
|