@flaunch/sdk 0.9.8 → 0.9.10
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/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/FlaunchZapClient.d.ts +29 -0
- package/dist/clients/FlaunchZapClient.d.ts.map +1 -1
- package/dist/helpers/index.cjs.map +1 -1
- package/dist/helpers/index.js.map +1 -1
- package/dist/index.cjs.js +1030 -902
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +1031 -904
- 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 +25 -3
- package/dist/sdk/FlaunchSDK.d.ts.map +1 -1
- package/dist/types.d.ts +24 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -5761,6 +5761,10 @@ const StakingManagerAddress = {
|
|
|
5761
5761
|
[base.id]: "0xec0069F8DBbbC94058dc895000dd38ef40b3125d",
|
|
5762
5762
|
[baseSepolia.id]: "0xB8f1cb6B4Ff8f07149276bbfA617aed7bd32d20D",
|
|
5763
5763
|
};
|
|
5764
|
+
const BuyBackManagerAddress = {
|
|
5765
|
+
[base.id]: "0x3AAF3b1D8cD5b61C77f99bA7cdf41E9eC0Ba8a3f",
|
|
5766
|
+
[baseSepolia.id]: "0xc3947EC9d687053bBA72b36Fd6b2567e775E82C7",
|
|
5767
|
+
};
|
|
5764
5768
|
/** Verifiers */
|
|
5765
5769
|
const TokenImporterAddress = {
|
|
5766
5770
|
[base.id]: "0xb47af90ae61bc916ea4b4bacffae4570e7435842",
|
|
@@ -13777,195 +13781,485 @@ class ReadWriteFlaunchPositionManagerV1_1 extends ReadFlaunchPositionManagerV1_1
|
|
|
13777
13781
|
}
|
|
13778
13782
|
}
|
|
13779
13783
|
|
|
13780
|
-
|
|
13781
|
-
|
|
13782
|
-
|
|
13783
|
-
|
|
13784
|
-
|
|
13785
|
-
|
|
13786
|
-
|
|
13787
|
-
|
|
13788
|
-
|
|
13789
|
-
|
|
13790
|
-
|
|
13791
|
-
|
|
13792
|
-
|
|
13793
|
-
|
|
13794
|
-
|
|
13795
|
-
|
|
13796
|
-
|
|
13797
|
-
|
|
13798
|
-
|
|
13799
|
-
|
|
13800
|
-
|
|
13801
|
-
|
|
13802
|
-
|
|
13803
|
-
|
|
13804
|
-
|
|
13805
|
-
|
|
13806
|
-
|
|
13807
|
-
|
|
13808
|
-
|
|
13809
|
-
|
|
13810
|
-
|
|
13811
|
-
|
|
13812
|
-
|
|
13813
|
-
});
|
|
13814
|
-
return premineCostInWeiWithSlippage;
|
|
13784
|
+
// our min/max tick range that is valid for the tick spacing (60)
|
|
13785
|
+
const TickFinder = {
|
|
13786
|
+
MIN_TICK: -887220,
|
|
13787
|
+
MAX_TICK: 887220,
|
|
13788
|
+
};
|
|
13789
|
+
const Q96 = 2n ** 96n;
|
|
13790
|
+
const Q192 = 2n ** 192n;
|
|
13791
|
+
const TICK_SPACING = 60;
|
|
13792
|
+
const getPoolId = (poolKey) => {
|
|
13793
|
+
// Pack the data in the same order as Solidity struct
|
|
13794
|
+
const packed = viem.concat([
|
|
13795
|
+
viem.pad(poolKey.currency0, { size: 32 }), // address padded to 32 bytes
|
|
13796
|
+
viem.pad(poolKey.currency1, { size: 32 }), // address padded to 32 bytes
|
|
13797
|
+
viem.pad(viem.toHex(poolKey.fee), { size: 32 }), // uint24 padded to 32 bytes
|
|
13798
|
+
viem.pad(viem.toHex(poolKey.tickSpacing), { size: 32 }), // int24 padded to 32 bytes
|
|
13799
|
+
viem.pad(poolKey.hooks, { size: 32 }), // address padded to 32 bytes
|
|
13800
|
+
]);
|
|
13801
|
+
return viem.keccak256(packed);
|
|
13802
|
+
};
|
|
13803
|
+
const orderPoolKey = (poolKey) => {
|
|
13804
|
+
const [currency0, currency1] = poolKey.currency0 < poolKey.currency1
|
|
13805
|
+
? [poolKey.currency0, poolKey.currency1]
|
|
13806
|
+
: [poolKey.currency1, poolKey.currency0];
|
|
13807
|
+
return {
|
|
13808
|
+
...poolKey,
|
|
13809
|
+
currency0,
|
|
13810
|
+
currency1,
|
|
13811
|
+
};
|
|
13812
|
+
};
|
|
13813
|
+
const getValidTick = ({ tick, tickSpacing, roundDown = true, }) => {
|
|
13814
|
+
// If the tick is already valid, exit early
|
|
13815
|
+
if (tick % tickSpacing === 0) {
|
|
13816
|
+
return tick;
|
|
13815
13817
|
}
|
|
13816
|
-
|
|
13817
|
-
|
|
13818
|
-
|
|
13819
|
-
|
|
13820
|
-
|
|
13821
|
-
amount: flaunchingFee,
|
|
13822
|
-
slippage: (params.slippagePercent ?? 0 / 100).toFixed(18).toString(),
|
|
13823
|
-
swapType: "EXACT_OUT",
|
|
13824
|
-
});
|
|
13825
|
-
return flaunchingFeeWithSlippage;
|
|
13818
|
+
// Division that rounds towards zero (like Solidity)
|
|
13819
|
+
let validTick = Math.trunc(tick / tickSpacing) * tickSpacing;
|
|
13820
|
+
// Handle negative ticks (Solidity behavior)
|
|
13821
|
+
if (tick < 0 && tick % tickSpacing !== 0) {
|
|
13822
|
+
validTick -= tickSpacing;
|
|
13826
13823
|
}
|
|
13827
|
-
|
|
13828
|
-
|
|
13829
|
-
|
|
13830
|
-
ethRequiredToFlaunch(params) {
|
|
13831
|
-
return this.contract.read("calculateFee", {
|
|
13832
|
-
_premineAmount: params.premineAmount ?? 0n,
|
|
13833
|
-
_slippage: params.slippagePercent
|
|
13834
|
-
? BigInt(params.slippagePercent * 100)
|
|
13835
|
-
: 0n,
|
|
13836
|
-
_initialPriceParams: params.initialPriceParams,
|
|
13837
|
-
});
|
|
13824
|
+
// If not rounding down, add TICK_SPACING to get the upper tick
|
|
13825
|
+
if (!roundDown) {
|
|
13826
|
+
validTick += tickSpacing;
|
|
13838
13827
|
}
|
|
13839
|
-
|
|
13840
|
-
|
|
13841
|
-
|
|
13842
|
-
|
|
13843
|
-
|
|
13844
|
-
|
|
13845
|
-
|
|
13828
|
+
return validTick;
|
|
13829
|
+
};
|
|
13830
|
+
// Rounds up or down to the nearest tick
|
|
13831
|
+
const getNearestUsableTick = ({ tick, tickSpacing, }) => {
|
|
13832
|
+
const rounded = Math.round(tick / tickSpacing) * tickSpacing;
|
|
13833
|
+
return Math.max(TickFinder.MIN_TICK, Math.min(TickFinder.MAX_TICK, rounded));
|
|
13834
|
+
};
|
|
13835
|
+
const getAmount0ForLiquidity = (sqrtRatioAX96, sqrtRatioBX96, liquidity) => {
|
|
13836
|
+
let [sqrtRatioA, sqrtRatioB] = [sqrtRatioAX96, sqrtRatioBX96];
|
|
13837
|
+
if (sqrtRatioA > sqrtRatioB) {
|
|
13838
|
+
[sqrtRatioA, sqrtRatioB] = [sqrtRatioB, sqrtRatioA];
|
|
13846
13839
|
}
|
|
13847
|
-
|
|
13848
|
-
|
|
13849
|
-
|
|
13850
|
-
|
|
13851
|
-
|
|
13852
|
-
|
|
13853
|
-
|
|
13854
|
-
|
|
13855
|
-
|
|
13856
|
-
|
|
13857
|
-
|
|
13858
|
-
], [initialMCapInUSDCWei]);
|
|
13859
|
-
const fairLaunchInBps = BigInt(params.fairLaunchPercent * 100);
|
|
13860
|
-
const creatorFeeAllocationInBps = params.creatorFeeAllocationPercent * 100;
|
|
13861
|
-
const ethRequired = await this.ethRequiredToFlaunch({
|
|
13862
|
-
premineAmount: params.premineAmount ?? 0n,
|
|
13863
|
-
initialPriceParams,
|
|
13864
|
-
slippagePercent: 5,
|
|
13865
|
-
});
|
|
13866
|
-
const _treasuryManagerParams = params.treasuryManagerParams
|
|
13867
|
-
? {
|
|
13868
|
-
manager: params.treasuryManagerParams.manager ?? viem.zeroAddress,
|
|
13869
|
-
permissions: params.treasuryManagerParams.permissions ?? exports.Permissions.OPEN,
|
|
13870
|
-
initializeData: params.treasuryManagerParams.initializeData ?? "0x",
|
|
13871
|
-
depositData: params.treasuryManagerParams.depositData ?? "0x",
|
|
13872
|
-
}
|
|
13873
|
-
: {
|
|
13874
|
-
manager: viem.zeroAddress,
|
|
13875
|
-
permissions: exports.Permissions.OPEN,
|
|
13876
|
-
initializeData: "0x",
|
|
13877
|
-
depositData: "0x",
|
|
13878
|
-
};
|
|
13879
|
-
const feeCalculatorParams = params.trustedSignerSettings
|
|
13880
|
-
? viem.encodeAbiParameters([
|
|
13881
|
-
{ type: "bool", name: "enabled" },
|
|
13882
|
-
{ type: "uint256", name: "walletCap" },
|
|
13883
|
-
{ type: "uint256", name: "txCap" },
|
|
13884
|
-
], [
|
|
13885
|
-
params.trustedSignerSettings.enabled,
|
|
13886
|
-
params.trustedSignerSettings.walletCap ?? 0n,
|
|
13887
|
-
params.trustedSignerSettings.txCap ?? 0n,
|
|
13888
|
-
])
|
|
13889
|
-
: "0x";
|
|
13890
|
-
const _premineSwapHookData = params.trustedSignerSettings?.enabled
|
|
13891
|
-
? viem.encodeAbiParameters([
|
|
13892
|
-
{ type: "address", name: "referrer" },
|
|
13893
|
-
{
|
|
13894
|
-
type: "tuple",
|
|
13895
|
-
components: [
|
|
13896
|
-
{ type: "uint256", name: "deadline" },
|
|
13897
|
-
{ type: "bytes", name: "signature" },
|
|
13898
|
-
],
|
|
13899
|
-
},
|
|
13900
|
-
], [
|
|
13901
|
-
viem.zeroAddress,
|
|
13902
|
-
{
|
|
13903
|
-
deadline: BigInt(params.trustedSignerSettings.premineSignedMessage?.deadline ?? 0),
|
|
13904
|
-
signature: params.trustedSignerSettings.premineSignedMessage?.signature ??
|
|
13905
|
-
"0x",
|
|
13906
|
-
},
|
|
13907
|
-
])
|
|
13908
|
-
: "0x";
|
|
13909
|
-
return this.contract.write("flaunch", {
|
|
13910
|
-
_flaunchParams: {
|
|
13911
|
-
name: params.name,
|
|
13912
|
-
symbol: params.symbol,
|
|
13913
|
-
tokenUri: params.tokenUri,
|
|
13914
|
-
initialTokenFairLaunch: (this.TOTAL_SUPPLY * fairLaunchInBps) / 10000n,
|
|
13915
|
-
fairLaunchDuration: BigInt(params.fairLaunchDuration),
|
|
13916
|
-
premineAmount: params.premineAmount ?? 0n,
|
|
13917
|
-
creator: params.creator,
|
|
13918
|
-
creatorFeeAllocation: creatorFeeAllocationInBps,
|
|
13919
|
-
flaunchAt: params.flaunchAt ?? 0n,
|
|
13920
|
-
initialPriceParams,
|
|
13921
|
-
feeCalculatorParams,
|
|
13922
|
-
},
|
|
13923
|
-
_trustedFeeSigner: params.trustedSignerSettings?.trustedFeeSigner ?? viem.zeroAddress,
|
|
13924
|
-
_premineSwapHookData,
|
|
13925
|
-
_treasuryManagerParams: {
|
|
13926
|
-
..._treasuryManagerParams,
|
|
13927
|
-
permissions: getPermissionsAddress(_treasuryManagerParams.permissions, this.chainId),
|
|
13928
|
-
},
|
|
13929
|
-
_whitelistParams: {
|
|
13930
|
-
merkleRoot: viem.zeroHash,
|
|
13931
|
-
merkleIPFSHash: "",
|
|
13932
|
-
maxTokens: 0n,
|
|
13933
|
-
},
|
|
13934
|
-
_airdropParams: {
|
|
13935
|
-
airdropIndex: 0n,
|
|
13936
|
-
airdropAmount: 0n,
|
|
13937
|
-
airdropEndTime: 0n,
|
|
13938
|
-
merkleRoot: viem.zeroHash,
|
|
13939
|
-
merkleIPFSHash: "",
|
|
13940
|
-
},
|
|
13941
|
-
}, {
|
|
13942
|
-
value: ethRequired,
|
|
13943
|
-
});
|
|
13840
|
+
const leftShiftedLiquidity = liquidity << 96n;
|
|
13841
|
+
const sqrtDiff = sqrtRatioB - sqrtRatioA;
|
|
13842
|
+
const multipliedRes = leftShiftedLiquidity * sqrtDiff;
|
|
13843
|
+
const numerator = multipliedRes / sqrtRatioB;
|
|
13844
|
+
const amount0 = numerator / sqrtRatioA;
|
|
13845
|
+
return amount0;
|
|
13846
|
+
};
|
|
13847
|
+
const getAmount1ForLiquidity = (sqrtRatioAX96, sqrtRatioBX96, liquidity) => {
|
|
13848
|
+
let [sqrtRatioA, sqrtRatioB] = [sqrtRatioAX96, sqrtRatioBX96];
|
|
13849
|
+
if (sqrtRatioA > sqrtRatioB) {
|
|
13850
|
+
[sqrtRatioA, sqrtRatioB] = [sqrtRatioB, sqrtRatioA];
|
|
13944
13851
|
}
|
|
13945
|
-
|
|
13946
|
-
|
|
13947
|
-
|
|
13948
|
-
|
|
13949
|
-
|
|
13950
|
-
|
|
13951
|
-
|
|
13952
|
-
|
|
13953
|
-
|
|
13852
|
+
const sqrtDiff = sqrtRatioB - sqrtRatioA;
|
|
13853
|
+
const multipliedRes = liquidity * sqrtDiff;
|
|
13854
|
+
const amount1 = multipliedRes / 2n ** 96n;
|
|
13855
|
+
return amount1;
|
|
13856
|
+
};
|
|
13857
|
+
const getSqrtPriceX96FromTick = (tick) => {
|
|
13858
|
+
const absTick = tick < 0 ? BigInt(-tick) : BigInt(tick);
|
|
13859
|
+
if (absTick > TickFinder.MAX_TICK) {
|
|
13860
|
+
throw new Error("Tick out of range");
|
|
13954
13861
|
}
|
|
13955
|
-
|
|
13956
|
-
|
|
13957
|
-
|
|
13958
|
-
|
|
13959
|
-
|
|
13960
|
-
|
|
13961
|
-
|
|
13962
|
-
|
|
13963
|
-
|
|
13964
|
-
|
|
13965
|
-
|
|
13966
|
-
|
|
13967
|
-
|
|
13968
|
-
|
|
13862
|
+
let ratio = (absTick & 1n) !== 0n
|
|
13863
|
+
? 0xfffcb933bd6fad37aa2d162d1a594001n
|
|
13864
|
+
: 0x100000000000000000000000000000000n;
|
|
13865
|
+
if ((absTick & 2n) !== 0n)
|
|
13866
|
+
ratio = (ratio * 0xfff97272373d413259a46990580e213an) >> 128n;
|
|
13867
|
+
if ((absTick & 4n) !== 0n)
|
|
13868
|
+
ratio = (ratio * 0xfff2e50f5f656932ef12357cf3c7fdccn) >> 128n;
|
|
13869
|
+
if ((absTick & 8n) !== 0n)
|
|
13870
|
+
ratio = (ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0n) >> 128n;
|
|
13871
|
+
if ((absTick & 16n) !== 0n)
|
|
13872
|
+
ratio = (ratio * 0xffcb9843d60f6159c9db58835c926644n) >> 128n;
|
|
13873
|
+
if ((absTick & 32n) !== 0n)
|
|
13874
|
+
ratio = (ratio * 0xff973b41fa98c081472e6896dfb254c0n) >> 128n;
|
|
13875
|
+
if ((absTick & 64n) !== 0n)
|
|
13876
|
+
ratio = (ratio * 0xff2ea16466c96a3843ec78b326b52861n) >> 128n;
|
|
13877
|
+
if ((absTick & 128n) !== 0n)
|
|
13878
|
+
ratio = (ratio * 0xfe5dee046a99a2a811c461f1969c3053n) >> 128n;
|
|
13879
|
+
if ((absTick & 256n) !== 0n)
|
|
13880
|
+
ratio = (ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4n) >> 128n;
|
|
13881
|
+
if ((absTick & 512n) !== 0n)
|
|
13882
|
+
ratio = (ratio * 0xf987a7253ac413176f2b074cf7815e54n) >> 128n;
|
|
13883
|
+
if ((absTick & 1024n) !== 0n)
|
|
13884
|
+
ratio = (ratio * 0xf3392b0822b70005940c7a398e4b70f3n) >> 128n;
|
|
13885
|
+
if ((absTick & 2048n) !== 0n)
|
|
13886
|
+
ratio = (ratio * 0xe7159475a2c29b7443b29c7fa6e889d9n) >> 128n;
|
|
13887
|
+
if ((absTick & 4096n) !== 0n)
|
|
13888
|
+
ratio = (ratio * 0xd097f3bdfd2022b8845ad8f792aa5825n) >> 128n;
|
|
13889
|
+
if ((absTick & 8192n) !== 0n)
|
|
13890
|
+
ratio = (ratio * 0xa9f746462d870fdf8a65dc1f90e061e5n) >> 128n;
|
|
13891
|
+
if ((absTick & 16384n) !== 0n)
|
|
13892
|
+
ratio = (ratio * 0x70d869a156d2a1b890bb3df62baf32f7n) >> 128n;
|
|
13893
|
+
if ((absTick & 32768n) !== 0n)
|
|
13894
|
+
ratio = (ratio * 0x31be135f97d08fd981231505542fcfa6n) >> 128n;
|
|
13895
|
+
if ((absTick & 65536n) !== 0n)
|
|
13896
|
+
ratio = (ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9n) >> 128n;
|
|
13897
|
+
if ((absTick & 131072n) !== 0n)
|
|
13898
|
+
ratio = (ratio * 0x5d6af8dedb81196699c329225ee604n) >> 128n;
|
|
13899
|
+
if ((absTick & 262144n) !== 0n)
|
|
13900
|
+
ratio = (ratio * 0x2216e584f5fa1ea926041bedfe98n) >> 128n;
|
|
13901
|
+
if ((absTick & 524288n) !== 0n)
|
|
13902
|
+
ratio = (ratio * 0x48a170391f7dc42444e8fa2n) >> 128n;
|
|
13903
|
+
if (tick > 0) {
|
|
13904
|
+
ratio = (2n ** 256n - 1n) / ratio;
|
|
13905
|
+
}
|
|
13906
|
+
// Convert from Q128.128 to Q128.96
|
|
13907
|
+
const resultShifted = ratio >> 32n;
|
|
13908
|
+
if (ratio % (1n << 32n) === 0n) {
|
|
13909
|
+
return resultShifted;
|
|
13910
|
+
}
|
|
13911
|
+
return resultShifted + 1n;
|
|
13912
|
+
};
|
|
13913
|
+
const calculateUnderlyingTokenBalances = (liquidity, tickLower, tickUpper, tickCurrent) => {
|
|
13914
|
+
const sqrtPriceCurrentX96 = getSqrtPriceX96FromTick(tickCurrent);
|
|
13915
|
+
const sqrtPriceLowerX96 = getSqrtPriceX96FromTick(tickLower);
|
|
13916
|
+
const sqrtPriceUpperX96 = getSqrtPriceX96FromTick(tickUpper);
|
|
13917
|
+
let amount0 = 0n;
|
|
13918
|
+
let amount1 = 0n;
|
|
13919
|
+
if (sqrtPriceCurrentX96 <= sqrtPriceLowerX96) {
|
|
13920
|
+
// Current price is below the position range
|
|
13921
|
+
amount0 = getAmount0ForLiquidity(sqrtPriceLowerX96, sqrtPriceUpperX96, liquidity);
|
|
13922
|
+
}
|
|
13923
|
+
else if (sqrtPriceCurrentX96 < sqrtPriceUpperX96) {
|
|
13924
|
+
// Current price is within the position range
|
|
13925
|
+
amount0 = getAmount0ForLiquidity(sqrtPriceCurrentX96, sqrtPriceUpperX96, liquidity);
|
|
13926
|
+
amount1 = getAmount1ForLiquidity(sqrtPriceLowerX96, sqrtPriceCurrentX96, liquidity);
|
|
13927
|
+
}
|
|
13928
|
+
else {
|
|
13929
|
+
// Current price is above the position range
|
|
13930
|
+
amount1 = getAmount1ForLiquidity(sqrtPriceLowerX96, sqrtPriceUpperX96, liquidity);
|
|
13931
|
+
}
|
|
13932
|
+
return { amount0, amount1 };
|
|
13933
|
+
};
|
|
13934
|
+
// Helper function to convert price ratio to tick with decimal handling
|
|
13935
|
+
const priceRatioToTick = ({ priceInput, isDirection1Per0, decimals0, decimals1, spacing, shouldGetNearestUsableTick = true, }) => {
|
|
13936
|
+
if (!priceInput || isNaN(Number(priceInput)))
|
|
13937
|
+
return 0;
|
|
13938
|
+
const inputPrice = Number(priceInput);
|
|
13939
|
+
try {
|
|
13940
|
+
// For Uniswap v3/v4, the tick represents price as: price = 1.0001^tick
|
|
13941
|
+
// where price = amount1/amount0 in their raw decimal format
|
|
13942
|
+
let priceRatio;
|
|
13943
|
+
if (isDirection1Per0) {
|
|
13944
|
+
// Input is token1 per token0 (e.g., memecoin per flETH)
|
|
13945
|
+
// Convert from human-readable to raw: divide by (10^decimals0 / 10^decimals1)
|
|
13946
|
+
priceRatio = inputPrice / Math.pow(10, decimals0 - decimals1);
|
|
13947
|
+
}
|
|
13948
|
+
else {
|
|
13949
|
+
// Input is token0 per token1 (e.g., flETH per memecoin)
|
|
13950
|
+
// Invert to get token1 per token0, then convert to raw
|
|
13951
|
+
priceRatio = 1 / inputPrice / Math.pow(10, decimals0 - decimals1);
|
|
13952
|
+
}
|
|
13953
|
+
// Calculate tick: tick = log(price) / log(1.0001)
|
|
13954
|
+
const tick = Math.log(priceRatio) / Math.log(1.0001);
|
|
13955
|
+
if (shouldGetNearestUsableTick) {
|
|
13956
|
+
return getValidTick({
|
|
13957
|
+
tick: Math.round(tick),
|
|
13958
|
+
tickSpacing: spacing,
|
|
13959
|
+
});
|
|
13960
|
+
}
|
|
13961
|
+
else {
|
|
13962
|
+
return Math.round(tick);
|
|
13963
|
+
}
|
|
13964
|
+
}
|
|
13965
|
+
catch (error) {
|
|
13966
|
+
console.error("Error converting price to tick:", error);
|
|
13967
|
+
// Fallback to basic calculation
|
|
13968
|
+
const rawTick = Math.floor(Math.log(inputPrice) / Math.log(1.0001));
|
|
13969
|
+
if (shouldGetNearestUsableTick) {
|
|
13970
|
+
return getValidTick({
|
|
13971
|
+
tick: rawTick,
|
|
13972
|
+
tickSpacing: spacing,
|
|
13973
|
+
});
|
|
13974
|
+
}
|
|
13975
|
+
else {
|
|
13976
|
+
return rawTick;
|
|
13977
|
+
}
|
|
13978
|
+
}
|
|
13979
|
+
};
|
|
13980
|
+
/**
|
|
13981
|
+
* Accurate liquidity calculation using proper Uniswap v3/v4 math
|
|
13982
|
+
*/
|
|
13983
|
+
const getLiquidityFromAmounts = (params) => {
|
|
13984
|
+
const sqrtRatioCurrentX96 = getSqrtPriceX96FromTick(params.currentTick);
|
|
13985
|
+
let sqrtRatioAX96 = getSqrtPriceX96FromTick(params.tickLower);
|
|
13986
|
+
let sqrtRatioBX96 = getSqrtPriceX96FromTick(params.tickUpper);
|
|
13987
|
+
if (sqrtRatioAX96 > sqrtRatioBX96) {
|
|
13988
|
+
[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
|
|
13989
|
+
}
|
|
13990
|
+
if (sqrtRatioCurrentX96 <= sqrtRatioAX96) {
|
|
13991
|
+
return maxLiquidityForAmount0Precise(sqrtRatioAX96, sqrtRatioBX96, params.amount0);
|
|
13992
|
+
}
|
|
13993
|
+
else if (sqrtRatioCurrentX96 < sqrtRatioBX96) {
|
|
13994
|
+
const liquidity0 = maxLiquidityForAmount0Precise(sqrtRatioCurrentX96, sqrtRatioBX96, params.amount0);
|
|
13995
|
+
const liquidity1 = maxLiquidityForAmount1(sqrtRatioAX96, sqrtRatioCurrentX96, params.amount1);
|
|
13996
|
+
return liquidity0 < liquidity1 ? liquidity0 : liquidity1;
|
|
13997
|
+
}
|
|
13998
|
+
else {
|
|
13999
|
+
return maxLiquidityForAmount1(sqrtRatioAX96, sqrtRatioBX96, params.amount1);
|
|
14000
|
+
}
|
|
14001
|
+
};
|
|
14002
|
+
/**
|
|
14003
|
+
* Returns a precise maximum amount of liquidity received for a given amount of token 0 by dividing by Q64 instead of Q96 in the intermediate step,
|
|
14004
|
+
* and shifting the subtracted ratio left by 32 bits.
|
|
14005
|
+
* @param sqrtRatioAX96 The price at the lower boundary
|
|
14006
|
+
* @param sqrtRatioBX96 The price at the upper boundary
|
|
14007
|
+
* @param amount0 The token0 amount
|
|
14008
|
+
* @returns liquidity for amount0, precise
|
|
14009
|
+
*/
|
|
14010
|
+
function maxLiquidityForAmount0Precise(sqrtRatioAX96, sqrtRatioBX96, amount0) {
|
|
14011
|
+
if (sqrtRatioAX96 > sqrtRatioBX96) {
|
|
14012
|
+
[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
|
|
14013
|
+
}
|
|
14014
|
+
// Handle edge case where sqrt ratios are equal (division by zero)
|
|
14015
|
+
if (sqrtRatioAX96 === sqrtRatioBX96) {
|
|
14016
|
+
return 0n;
|
|
14017
|
+
}
|
|
14018
|
+
const Q96 = 2n ** 96n;
|
|
14019
|
+
const numerator = amount0 * sqrtRatioAX96 * sqrtRatioBX96;
|
|
14020
|
+
const denominator = Q96 * (sqrtRatioBX96 - sqrtRatioAX96);
|
|
14021
|
+
return numerator / denominator;
|
|
14022
|
+
}
|
|
14023
|
+
/**
|
|
14024
|
+
* Computes the maximum amount of liquidity received for a given amount of token1
|
|
14025
|
+
* @param sqrtRatioAX96 The price at the lower tick boundary
|
|
14026
|
+
* @param sqrtRatioBX96 The price at the upper tick boundary
|
|
14027
|
+
* @param amount1 The token1 amount
|
|
14028
|
+
* @returns liquidity for amount1
|
|
14029
|
+
*/
|
|
14030
|
+
function maxLiquidityForAmount1(sqrtRatioAX96, sqrtRatioBX96, amount1) {
|
|
14031
|
+
if (sqrtRatioAX96 > sqrtRatioBX96) {
|
|
14032
|
+
[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
|
|
14033
|
+
}
|
|
14034
|
+
// Handle edge case where sqrt ratios are equal (division by zero)
|
|
14035
|
+
if (sqrtRatioAX96 === sqrtRatioBX96) {
|
|
14036
|
+
return 0n;
|
|
14037
|
+
}
|
|
14038
|
+
const Q96 = 2n ** 96n;
|
|
14039
|
+
return (amount1 * Q96) / (sqrtRatioBX96 - sqrtRatioAX96);
|
|
14040
|
+
}
|
|
14041
|
+
/**
|
|
14042
|
+
* Calculate the actual amounts needed for a given liquidity
|
|
14043
|
+
* This prevents MaximumAmountExceeded errors by ensuring we provide sufficient maximums
|
|
14044
|
+
*/
|
|
14045
|
+
const getAmountsForLiquidity = (params) => {
|
|
14046
|
+
// Handle zero liquidity case
|
|
14047
|
+
if (params.liquidity === 0n) {
|
|
14048
|
+
return { amount0: 0n, amount1: 0n };
|
|
14049
|
+
}
|
|
14050
|
+
const sqrtRatioCurrentX96 = getSqrtPriceX96FromTick(params.currentTick);
|
|
14051
|
+
let sqrtRatioAX96 = getSqrtPriceX96FromTick(params.tickLower);
|
|
14052
|
+
let sqrtRatioBX96 = getSqrtPriceX96FromTick(params.tickUpper);
|
|
14053
|
+
if (sqrtRatioAX96 > sqrtRatioBX96) {
|
|
14054
|
+
[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
|
|
14055
|
+
}
|
|
14056
|
+
let amount0 = 0n;
|
|
14057
|
+
let amount1 = 0n;
|
|
14058
|
+
if (sqrtRatioCurrentX96 <= sqrtRatioAX96) {
|
|
14059
|
+
// Current price is below the range, only token0 needed
|
|
14060
|
+
amount0 = getAmount0ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, params.liquidity);
|
|
14061
|
+
}
|
|
14062
|
+
else if (sqrtRatioCurrentX96 < sqrtRatioBX96) {
|
|
14063
|
+
// Current price is within the range, need both tokens
|
|
14064
|
+
amount0 = getAmount0ForLiquidity(sqrtRatioCurrentX96, sqrtRatioBX96, params.liquidity);
|
|
14065
|
+
amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioCurrentX96, params.liquidity);
|
|
14066
|
+
}
|
|
14067
|
+
else {
|
|
14068
|
+
// Current price is above the range, only token1 needed
|
|
14069
|
+
amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, params.liquidity);
|
|
14070
|
+
}
|
|
14071
|
+
return { amount0, amount1 };
|
|
14072
|
+
};
|
|
14073
|
+
|
|
14074
|
+
/**
|
|
14075
|
+
* Base client for interacting with the FlaunchZap contract in read-only mode
|
|
14076
|
+
* Provides basic contract initialization
|
|
14077
|
+
*/
|
|
14078
|
+
class ReadFlaunchZap {
|
|
14079
|
+
/**
|
|
14080
|
+
* Creates a new ReadFlaunchZap instance
|
|
14081
|
+
* @param chainId - The chain ID of the contract
|
|
14082
|
+
* @param address - The address of the FlaunchZap contract
|
|
14083
|
+
* @param drift - Optional drift instance for contract interactions (creates new instance if not provided)
|
|
14084
|
+
* @throws Error if address is not provided
|
|
14085
|
+
*/
|
|
14086
|
+
constructor(chainId, address, drift$1 = drift.createDrift()) {
|
|
14087
|
+
this.TOTAL_SUPPLY = 100n * 10n ** 27n; // 100 Billion tokens in wei
|
|
14088
|
+
this.chainId = chainId;
|
|
14089
|
+
this.drift = drift$1;
|
|
14090
|
+
if (!address) {
|
|
14091
|
+
throw new Error("Address is required");
|
|
14092
|
+
}
|
|
14093
|
+
this.contract = drift$1.contract({
|
|
14094
|
+
abi: FlaunchZapAbi,
|
|
14095
|
+
address,
|
|
14096
|
+
});
|
|
14097
|
+
this.readPositionManagerV1_1 = new ReadFlaunchPositionManagerV1_1(FlaunchPositionManagerV1_1Address[this.chainId], drift$1);
|
|
14098
|
+
}
|
|
14099
|
+
async getPremineCostInWei(params) {
|
|
14100
|
+
const mcapInWei = await this.readPositionManagerV1_1.getFlaunchingMarketCap(params.initialPriceParams);
|
|
14101
|
+
const premineCostInWei = (mcapInWei * params.premineAmount) / this.TOTAL_SUPPLY;
|
|
14102
|
+
// increase the premine cost by the slippage percent
|
|
14103
|
+
const premineCostInWeiWithSlippage = getAmountWithSlippage({
|
|
14104
|
+
amount: premineCostInWei,
|
|
14105
|
+
slippage: (params.slippagePercent ?? 0 / 100).toFixed(18).toString(),
|
|
14106
|
+
swapType: "EXACT_OUT", // as we know the output premine amount
|
|
14107
|
+
});
|
|
14108
|
+
return premineCostInWeiWithSlippage;
|
|
14109
|
+
}
|
|
14110
|
+
async getFlaunchingFee(params) {
|
|
14111
|
+
const readInitialPrice = new ReadInitialPrice(await this.readPositionManagerV1_1.initialPrice(), this.drift);
|
|
14112
|
+
const flaunchingFee = await readInitialPrice.getFlaunchingFee(params);
|
|
14113
|
+
// increase the flaunching fee by the slippage percent
|
|
14114
|
+
const flaunchingFeeWithSlippage = getAmountWithSlippage({
|
|
14115
|
+
amount: flaunchingFee,
|
|
14116
|
+
slippage: (params.slippagePercent ?? 0 / 100).toFixed(18).toString(),
|
|
14117
|
+
swapType: "EXACT_OUT",
|
|
14118
|
+
});
|
|
14119
|
+
return flaunchingFeeWithSlippage;
|
|
14120
|
+
}
|
|
14121
|
+
/**
|
|
14122
|
+
* Calculates the ETH required to flaunch a token, takes into account the ETH for premine and the flaunching fee
|
|
14123
|
+
*/
|
|
14124
|
+
ethRequiredToFlaunch(params) {
|
|
14125
|
+
return this.contract.read("calculateFee", {
|
|
14126
|
+
_premineAmount: params.premineAmount ?? 0n,
|
|
14127
|
+
_slippage: params.slippagePercent
|
|
14128
|
+
? BigInt(params.slippagePercent * 100)
|
|
14129
|
+
: 0n,
|
|
14130
|
+
_initialPriceParams: params.initialPriceParams,
|
|
14131
|
+
});
|
|
14132
|
+
}
|
|
14133
|
+
}
|
|
14134
|
+
/**
|
|
14135
|
+
* Extended client for interacting with the FlaunchZap contract with write capabilities
|
|
14136
|
+
*/
|
|
14137
|
+
class ReadWriteFlaunchZap extends ReadFlaunchZap {
|
|
14138
|
+
constructor(chainId, address, drift$1 = drift.createDrift()) {
|
|
14139
|
+
super(chainId, address, drift$1);
|
|
14140
|
+
}
|
|
14141
|
+
/**
|
|
14142
|
+
* Flaunches a new token, supports premine
|
|
14143
|
+
* @param params - Parameters for the flaunch
|
|
14144
|
+
* @returns Transaction response for the flaunch creation
|
|
14145
|
+
*/
|
|
14146
|
+
async flaunch(params) {
|
|
14147
|
+
const initialMCapInUSDCWei = viem.parseUnits(params.initialMarketCapUSD.toString(), 6);
|
|
14148
|
+
const initialPriceParams = viem.encodeAbiParameters([
|
|
14149
|
+
{
|
|
14150
|
+
type: "uint256",
|
|
14151
|
+
},
|
|
14152
|
+
], [initialMCapInUSDCWei]);
|
|
14153
|
+
const fairLaunchInBps = BigInt(params.fairLaunchPercent * 100);
|
|
14154
|
+
const creatorFeeAllocationInBps = params.creatorFeeAllocationPercent * 100;
|
|
14155
|
+
const ethRequired = await this.ethRequiredToFlaunch({
|
|
14156
|
+
premineAmount: params.premineAmount ?? 0n,
|
|
14157
|
+
initialPriceParams,
|
|
14158
|
+
slippagePercent: 5,
|
|
14159
|
+
});
|
|
14160
|
+
const _treasuryManagerParams = params.treasuryManagerParams
|
|
14161
|
+
? {
|
|
14162
|
+
manager: params.treasuryManagerParams.manager ?? viem.zeroAddress,
|
|
14163
|
+
permissions: params.treasuryManagerParams.permissions ?? exports.Permissions.OPEN,
|
|
14164
|
+
initializeData: params.treasuryManagerParams.initializeData ?? "0x",
|
|
14165
|
+
depositData: params.treasuryManagerParams.depositData ?? "0x",
|
|
14166
|
+
}
|
|
14167
|
+
: {
|
|
14168
|
+
manager: viem.zeroAddress,
|
|
14169
|
+
permissions: exports.Permissions.OPEN,
|
|
14170
|
+
initializeData: "0x",
|
|
14171
|
+
depositData: "0x",
|
|
14172
|
+
};
|
|
14173
|
+
const feeCalculatorParams = params.trustedSignerSettings
|
|
14174
|
+
? viem.encodeAbiParameters([
|
|
14175
|
+
{ type: "bool", name: "enabled" },
|
|
14176
|
+
{ type: "uint256", name: "walletCap" },
|
|
14177
|
+
{ type: "uint256", name: "txCap" },
|
|
14178
|
+
], [
|
|
14179
|
+
params.trustedSignerSettings.enabled,
|
|
14180
|
+
params.trustedSignerSettings.walletCap ?? 0n,
|
|
14181
|
+
params.trustedSignerSettings.txCap ?? 0n,
|
|
14182
|
+
])
|
|
14183
|
+
: "0x";
|
|
14184
|
+
const _premineSwapHookData = params.trustedSignerSettings?.enabled
|
|
14185
|
+
? viem.encodeAbiParameters([
|
|
14186
|
+
{ type: "address", name: "referrer" },
|
|
14187
|
+
{
|
|
14188
|
+
type: "tuple",
|
|
14189
|
+
components: [
|
|
14190
|
+
{ type: "uint256", name: "deadline" },
|
|
14191
|
+
{ type: "bytes", name: "signature" },
|
|
14192
|
+
],
|
|
14193
|
+
},
|
|
14194
|
+
], [
|
|
14195
|
+
viem.zeroAddress,
|
|
14196
|
+
{
|
|
14197
|
+
deadline: BigInt(params.trustedSignerSettings.premineSignedMessage?.deadline ?? 0),
|
|
14198
|
+
signature: params.trustedSignerSettings.premineSignedMessage?.signature ??
|
|
14199
|
+
"0x",
|
|
14200
|
+
},
|
|
14201
|
+
])
|
|
14202
|
+
: "0x";
|
|
14203
|
+
return this.contract.write("flaunch", {
|
|
14204
|
+
_flaunchParams: {
|
|
14205
|
+
name: params.name,
|
|
14206
|
+
symbol: params.symbol,
|
|
14207
|
+
tokenUri: params.tokenUri,
|
|
14208
|
+
initialTokenFairLaunch: (this.TOTAL_SUPPLY * fairLaunchInBps) / 10000n,
|
|
14209
|
+
fairLaunchDuration: BigInt(params.fairLaunchDuration),
|
|
14210
|
+
premineAmount: params.premineAmount ?? 0n,
|
|
14211
|
+
creator: params.creator,
|
|
14212
|
+
creatorFeeAllocation: creatorFeeAllocationInBps,
|
|
14213
|
+
flaunchAt: params.flaunchAt ?? 0n,
|
|
14214
|
+
initialPriceParams,
|
|
14215
|
+
feeCalculatorParams,
|
|
14216
|
+
},
|
|
14217
|
+
_trustedFeeSigner: params.trustedSignerSettings?.trustedFeeSigner ?? viem.zeroAddress,
|
|
14218
|
+
_premineSwapHookData,
|
|
14219
|
+
_treasuryManagerParams: {
|
|
14220
|
+
..._treasuryManagerParams,
|
|
14221
|
+
permissions: getPermissionsAddress(_treasuryManagerParams.permissions, this.chainId),
|
|
14222
|
+
},
|
|
14223
|
+
_whitelistParams: {
|
|
14224
|
+
merkleRoot: viem.zeroHash,
|
|
14225
|
+
merkleIPFSHash: "",
|
|
14226
|
+
maxTokens: 0n,
|
|
14227
|
+
},
|
|
14228
|
+
_airdropParams: {
|
|
14229
|
+
airdropIndex: 0n,
|
|
14230
|
+
airdropAmount: 0n,
|
|
14231
|
+
airdropEndTime: 0n,
|
|
14232
|
+
merkleRoot: viem.zeroHash,
|
|
14233
|
+
merkleIPFSHash: "",
|
|
14234
|
+
},
|
|
14235
|
+
}, {
|
|
14236
|
+
value: ethRequired,
|
|
14237
|
+
});
|
|
14238
|
+
}
|
|
14239
|
+
async flaunchIPFS(params) {
|
|
14240
|
+
const tokenUri = await generateTokenUri(params.name, params.symbol, {
|
|
14241
|
+
metadata: params.metadata,
|
|
14242
|
+
pinataConfig: params.pinataConfig,
|
|
14243
|
+
});
|
|
14244
|
+
return this.flaunch({
|
|
14245
|
+
...params,
|
|
14246
|
+
tokenUri,
|
|
14247
|
+
});
|
|
14248
|
+
}
|
|
14249
|
+
/**
|
|
14250
|
+
* Flaunches a new token for a revenue manager
|
|
14251
|
+
* @param params - Parameters for the flaunch with revenue manager
|
|
14252
|
+
* @param params.name - The name of the token
|
|
14253
|
+
* @param params.symbol - The symbol of the token
|
|
14254
|
+
* @param params.tokenUri - The URI containing the token metadata
|
|
14255
|
+
* @param params.fairLaunchPercent - Percentage of total supply to be used in fair launch (0-100)
|
|
14256
|
+
* @param params.fairLaunchDuration - Duration of fair launch in seconds
|
|
14257
|
+
* @param params.initialMarketCapUSD - Initial market cap in USD
|
|
14258
|
+
* @param params.creator - Address of the token creator
|
|
14259
|
+
* @param params.creatorFeeAllocationPercent - Percentage of fees allocated to creator (0-100)
|
|
14260
|
+
* @param params.protocolRecipient - Address to receive protocol fees
|
|
14261
|
+
* @param params.protocolFeePercent - Percentage of fees allocated to protocol (0-100)
|
|
14262
|
+
* @param params.flaunchAt - Optional timestamp when the flaunch should start
|
|
13969
14263
|
* @param params.premineAmount - Optional amount of tokens to premine
|
|
13970
14264
|
* @returns Transaction response for the flaunch creation
|
|
13971
14265
|
*/
|
|
@@ -14152,6 +14446,66 @@ class ReadWriteFlaunchZap extends ReadFlaunchZap {
|
|
|
14152
14446
|
_permissions: permissionsAddress,
|
|
14153
14447
|
});
|
|
14154
14448
|
}
|
|
14449
|
+
/**
|
|
14450
|
+
* Deploys a new BuyBack manager
|
|
14451
|
+
* @param params - Parameters for deploying the BuyBack manager
|
|
14452
|
+
* @param params.managerOwner - The address of the manager owner
|
|
14453
|
+
* @param params.creatorSharePercent - The % share that a creator will earn from their token (0-100)
|
|
14454
|
+
* @param params.ownerSharePercent - The % share that the manager owner will earn from their token (0-100)
|
|
14455
|
+
* @param params.buyBackPoolKey - The Uniswap V4 pool key configuration for the buyback pool
|
|
14456
|
+
* @param params.buyBackPoolKey.currency0 - The lower currency of the pool (sorted numerically)
|
|
14457
|
+
* @param params.buyBackPoolKey.currency1 - The higher currency of the pool (sorted numerically)
|
|
14458
|
+
* @param params.buyBackPoolKey.fee - The pool LP fee, capped at 1_000_000
|
|
14459
|
+
* @param params.buyBackPoolKey.tickSpacing - Tick spacing for the pool
|
|
14460
|
+
* @param params.buyBackPoolKey.hooks - The hooks address of the pool
|
|
14461
|
+
* @param params.permissions - The permissions for the BuyBack manager
|
|
14462
|
+
* @returns Transaction response
|
|
14463
|
+
*/
|
|
14464
|
+
deployBuyBackManager(params) {
|
|
14465
|
+
const permissionsAddress = getPermissionsAddress(params.permissions ?? exports.Permissions.OPEN, this.chainId);
|
|
14466
|
+
const VALID_SHARE_TOTAL = 10000000n; // 5 decimals as BigInt
|
|
14467
|
+
const buyBackManagerAddress = BuyBackManagerAddress[this.chainId];
|
|
14468
|
+
if (buyBackManagerAddress === viem.zeroAddress) {
|
|
14469
|
+
throw new Error(`BuyBackManager not deployed on chainId: ${this.chainId}`);
|
|
14470
|
+
}
|
|
14471
|
+
return this.contract.write("deployAndInitializeManager", {
|
|
14472
|
+
_managerImplementation: buyBackManagerAddress,
|
|
14473
|
+
_owner: params.managerOwner,
|
|
14474
|
+
_data: viem.encodeAbiParameters([
|
|
14475
|
+
{
|
|
14476
|
+
type: "tuple",
|
|
14477
|
+
components: [
|
|
14478
|
+
{ type: "uint256", name: "creatorShare" },
|
|
14479
|
+
{ type: "uint256", name: "ownerShare" },
|
|
14480
|
+
{
|
|
14481
|
+
type: "tuple",
|
|
14482
|
+
name: "buyBackPoolKey",
|
|
14483
|
+
components: [
|
|
14484
|
+
{ type: "address", name: "currency0" },
|
|
14485
|
+
{ type: "address", name: "currency1" },
|
|
14486
|
+
{ type: "uint24", name: "fee" },
|
|
14487
|
+
{ type: "int24", name: "tickSpacing" },
|
|
14488
|
+
{ type: "address", name: "hooks" },
|
|
14489
|
+
],
|
|
14490
|
+
},
|
|
14491
|
+
],
|
|
14492
|
+
},
|
|
14493
|
+
], [
|
|
14494
|
+
{
|
|
14495
|
+
creatorShare: (BigInt(params.creatorSharePercent) * VALID_SHARE_TOTAL) / 100n,
|
|
14496
|
+
ownerShare: (BigInt(params.ownerSharePercent) * VALID_SHARE_TOTAL) / 100n,
|
|
14497
|
+
buyBackPoolKey: orderPoolKey({
|
|
14498
|
+
currency0: params.buyBackPoolKey.currency0,
|
|
14499
|
+
currency1: params.buyBackPoolKey.currency1,
|
|
14500
|
+
fee: params.buyBackPoolKey.fee,
|
|
14501
|
+
tickSpacing: params.buyBackPoolKey.tickSpacing,
|
|
14502
|
+
hooks: params.buyBackPoolKey.hooks,
|
|
14503
|
+
}),
|
|
14504
|
+
},
|
|
14505
|
+
]),
|
|
14506
|
+
_permissions: permissionsAddress,
|
|
14507
|
+
});
|
|
14508
|
+
}
|
|
14155
14509
|
}
|
|
14156
14510
|
|
|
14157
14511
|
const FlaunchAbi = [
|
|
@@ -24729,803 +25083,513 @@ const MulticallAbi = [
|
|
|
24729
25083
|
type: "uint256",
|
|
24730
25084
|
},
|
|
24731
25085
|
],
|
|
24732
|
-
stateMutability: "view",
|
|
24733
|
-
type: "function",
|
|
24734
|
-
},
|
|
24735
|
-
{
|
|
24736
|
-
inputs: [],
|
|
24737
|
-
name: "getChainId",
|
|
24738
|
-
outputs: [
|
|
24739
|
-
{
|
|
24740
|
-
internalType: "uint256",
|
|
24741
|
-
name: "chainid",
|
|
24742
|
-
type: "uint256",
|
|
24743
|
-
},
|
|
24744
|
-
],
|
|
24745
|
-
stateMutability: "view",
|
|
24746
|
-
type: "function",
|
|
24747
|
-
},
|
|
24748
|
-
{
|
|
24749
|
-
inputs: [],
|
|
24750
|
-
name: "getCurrentBlockCoinbase",
|
|
24751
|
-
outputs: [
|
|
24752
|
-
{
|
|
24753
|
-
internalType: "address",
|
|
24754
|
-
name: "coinbase",
|
|
24755
|
-
type: "address",
|
|
24756
|
-
},
|
|
24757
|
-
],
|
|
24758
|
-
stateMutability: "view",
|
|
24759
|
-
type: "function",
|
|
24760
|
-
},
|
|
24761
|
-
{
|
|
24762
|
-
inputs: [],
|
|
24763
|
-
name: "getCurrentBlockDifficulty",
|
|
24764
|
-
outputs: [
|
|
24765
|
-
{
|
|
24766
|
-
internalType: "uint256",
|
|
24767
|
-
name: "difficulty",
|
|
24768
|
-
type: "uint256",
|
|
24769
|
-
},
|
|
24770
|
-
],
|
|
24771
|
-
stateMutability: "view",
|
|
24772
|
-
type: "function",
|
|
24773
|
-
},
|
|
24774
|
-
{
|
|
24775
|
-
inputs: [],
|
|
24776
|
-
name: "getCurrentBlockGasLimit",
|
|
24777
|
-
outputs: [
|
|
24778
|
-
{
|
|
24779
|
-
internalType: "uint256",
|
|
24780
|
-
name: "gaslimit",
|
|
24781
|
-
type: "uint256",
|
|
24782
|
-
},
|
|
24783
|
-
],
|
|
24784
|
-
stateMutability: "view",
|
|
24785
|
-
type: "function",
|
|
24786
|
-
},
|
|
24787
|
-
{
|
|
24788
|
-
inputs: [],
|
|
24789
|
-
name: "getCurrentBlockTimestamp",
|
|
24790
|
-
outputs: [
|
|
24791
|
-
{
|
|
24792
|
-
internalType: "uint256",
|
|
24793
|
-
name: "timestamp",
|
|
24794
|
-
type: "uint256",
|
|
24795
|
-
},
|
|
24796
|
-
],
|
|
24797
|
-
stateMutability: "view",
|
|
24798
|
-
type: "function",
|
|
24799
|
-
},
|
|
24800
|
-
{
|
|
24801
|
-
inputs: [
|
|
24802
|
-
{
|
|
24803
|
-
internalType: "address",
|
|
24804
|
-
name: "addr",
|
|
24805
|
-
type: "address",
|
|
24806
|
-
},
|
|
24807
|
-
],
|
|
24808
|
-
name: "getEthBalance",
|
|
24809
|
-
outputs: [
|
|
24810
|
-
{
|
|
24811
|
-
internalType: "uint256",
|
|
24812
|
-
name: "balance",
|
|
24813
|
-
type: "uint256",
|
|
24814
|
-
},
|
|
24815
|
-
],
|
|
24816
|
-
stateMutability: "view",
|
|
24817
|
-
type: "function",
|
|
24818
|
-
},
|
|
24819
|
-
{
|
|
24820
|
-
inputs: [],
|
|
24821
|
-
name: "getLastBlockHash",
|
|
24822
|
-
outputs: [
|
|
24823
|
-
{
|
|
24824
|
-
internalType: "bytes32",
|
|
24825
|
-
name: "blockHash",
|
|
24826
|
-
type: "bytes32",
|
|
24827
|
-
},
|
|
24828
|
-
],
|
|
24829
|
-
stateMutability: "view",
|
|
24830
|
-
type: "function",
|
|
24831
|
-
},
|
|
24832
|
-
{
|
|
24833
|
-
inputs: [
|
|
24834
|
-
{
|
|
24835
|
-
internalType: "bool",
|
|
24836
|
-
name: "requireSuccess",
|
|
24837
|
-
type: "bool",
|
|
24838
|
-
},
|
|
24839
|
-
{
|
|
24840
|
-
components: [
|
|
24841
|
-
{
|
|
24842
|
-
internalType: "address",
|
|
24843
|
-
name: "target",
|
|
24844
|
-
type: "address",
|
|
24845
|
-
},
|
|
24846
|
-
{
|
|
24847
|
-
internalType: "bytes",
|
|
24848
|
-
name: "callData",
|
|
24849
|
-
type: "bytes",
|
|
24850
|
-
},
|
|
24851
|
-
],
|
|
24852
|
-
internalType: "struct Multicall3.Call[]",
|
|
24853
|
-
name: "calls",
|
|
24854
|
-
type: "tuple[]",
|
|
24855
|
-
},
|
|
24856
|
-
],
|
|
24857
|
-
name: "tryAggregate",
|
|
24858
|
-
outputs: [
|
|
24859
|
-
{
|
|
24860
|
-
components: [
|
|
24861
|
-
{
|
|
24862
|
-
internalType: "bool",
|
|
24863
|
-
name: "success",
|
|
24864
|
-
type: "bool",
|
|
24865
|
-
},
|
|
24866
|
-
{
|
|
24867
|
-
internalType: "bytes",
|
|
24868
|
-
name: "returnData",
|
|
24869
|
-
type: "bytes",
|
|
24870
|
-
},
|
|
24871
|
-
],
|
|
24872
|
-
internalType: "struct Multicall3.Result[]",
|
|
24873
|
-
name: "returnData",
|
|
24874
|
-
type: "tuple[]",
|
|
24875
|
-
},
|
|
24876
|
-
],
|
|
24877
|
-
stateMutability: "payable",
|
|
25086
|
+
stateMutability: "view",
|
|
24878
25087
|
type: "function",
|
|
24879
25088
|
},
|
|
24880
25089
|
{
|
|
24881
|
-
inputs: [
|
|
25090
|
+
inputs: [],
|
|
25091
|
+
name: "getChainId",
|
|
25092
|
+
outputs: [
|
|
24882
25093
|
{
|
|
24883
|
-
internalType: "
|
|
24884
|
-
name: "
|
|
24885
|
-
type: "
|
|
25094
|
+
internalType: "uint256",
|
|
25095
|
+
name: "chainid",
|
|
25096
|
+
type: "uint256",
|
|
24886
25097
|
},
|
|
25098
|
+
],
|
|
25099
|
+
stateMutability: "view",
|
|
25100
|
+
type: "function",
|
|
25101
|
+
},
|
|
25102
|
+
{
|
|
25103
|
+
inputs: [],
|
|
25104
|
+
name: "getCurrentBlockCoinbase",
|
|
25105
|
+
outputs: [
|
|
24887
25106
|
{
|
|
24888
|
-
|
|
24889
|
-
|
|
24890
|
-
|
|
24891
|
-
name: "target",
|
|
24892
|
-
type: "address",
|
|
24893
|
-
},
|
|
24894
|
-
{
|
|
24895
|
-
internalType: "bytes",
|
|
24896
|
-
name: "callData",
|
|
24897
|
-
type: "bytes",
|
|
24898
|
-
},
|
|
24899
|
-
],
|
|
24900
|
-
internalType: "struct Multicall3.Call[]",
|
|
24901
|
-
name: "calls",
|
|
24902
|
-
type: "tuple[]",
|
|
25107
|
+
internalType: "address",
|
|
25108
|
+
name: "coinbase",
|
|
25109
|
+
type: "address",
|
|
24903
25110
|
},
|
|
24904
25111
|
],
|
|
24905
|
-
|
|
25112
|
+
stateMutability: "view",
|
|
25113
|
+
type: "function",
|
|
25114
|
+
},
|
|
25115
|
+
{
|
|
25116
|
+
inputs: [],
|
|
25117
|
+
name: "getCurrentBlockDifficulty",
|
|
24906
25118
|
outputs: [
|
|
24907
25119
|
{
|
|
24908
25120
|
internalType: "uint256",
|
|
24909
|
-
name: "
|
|
25121
|
+
name: "difficulty",
|
|
24910
25122
|
type: "uint256",
|
|
24911
25123
|
},
|
|
25124
|
+
],
|
|
25125
|
+
stateMutability: "view",
|
|
25126
|
+
type: "function",
|
|
25127
|
+
},
|
|
25128
|
+
{
|
|
25129
|
+
inputs: [],
|
|
25130
|
+
name: "getCurrentBlockGasLimit",
|
|
25131
|
+
outputs: [
|
|
24912
25132
|
{
|
|
24913
|
-
internalType: "
|
|
24914
|
-
name: "
|
|
24915
|
-
type: "
|
|
24916
|
-
},
|
|
24917
|
-
{
|
|
24918
|
-
components: [
|
|
24919
|
-
{
|
|
24920
|
-
internalType: "bool",
|
|
24921
|
-
name: "success",
|
|
24922
|
-
type: "bool",
|
|
24923
|
-
},
|
|
24924
|
-
{
|
|
24925
|
-
internalType: "bytes",
|
|
24926
|
-
name: "returnData",
|
|
24927
|
-
type: "bytes",
|
|
24928
|
-
},
|
|
24929
|
-
],
|
|
24930
|
-
internalType: "struct Multicall3.Result[]",
|
|
24931
|
-
name: "returnData",
|
|
24932
|
-
type: "tuple[]",
|
|
25133
|
+
internalType: "uint256",
|
|
25134
|
+
name: "gaslimit",
|
|
25135
|
+
type: "uint256",
|
|
24933
25136
|
},
|
|
24934
25137
|
],
|
|
24935
|
-
stateMutability: "
|
|
25138
|
+
stateMutability: "view",
|
|
24936
25139
|
type: "function",
|
|
24937
25140
|
},
|
|
24938
|
-
];
|
|
24939
|
-
|
|
24940
|
-
class ReadMulticall {
|
|
24941
|
-
constructor(drift) {
|
|
24942
|
-
// same address across all chains
|
|
24943
|
-
this.address = "0xcA11bde05977b3631167028862bE2a173976CA11";
|
|
24944
|
-
this.contract = drift.contract({
|
|
24945
|
-
abi: MulticallAbi,
|
|
24946
|
-
address: this.address,
|
|
24947
|
-
});
|
|
24948
|
-
}
|
|
24949
|
-
aggregate3(calls) {
|
|
24950
|
-
return this.contract.simulateWrite("aggregate3", {
|
|
24951
|
-
calls: calls.map((call) => ({
|
|
24952
|
-
target: call.target,
|
|
24953
|
-
allowFailure: true,
|
|
24954
|
-
callData: call.callData,
|
|
24955
|
-
})),
|
|
24956
|
-
});
|
|
24957
|
-
}
|
|
24958
|
-
}
|
|
24959
|
-
|
|
24960
|
-
class ReadRevenueManager {
|
|
24961
|
-
constructor(address, drift$1 = drift.createDrift()) {
|
|
24962
|
-
this.drift = drift$1;
|
|
24963
|
-
this.contract = drift$1.contract({
|
|
24964
|
-
abi: RevenueManagerAbi,
|
|
24965
|
-
address,
|
|
24966
|
-
});
|
|
24967
|
-
}
|
|
24968
|
-
/**
|
|
24969
|
-
* Gets the claimable balance of ETH for the recipient
|
|
24970
|
-
* @param recipient - The address of the recipient to check
|
|
24971
|
-
* @returns Promise<bigint> - The claimable balance of ETH
|
|
24972
|
-
*/
|
|
24973
|
-
balances(address) {
|
|
24974
|
-
return this.contract.read("balances", {
|
|
24975
|
-
_recipient: address,
|
|
24976
|
-
});
|
|
24977
|
-
}
|
|
24978
|
-
/**
|
|
24979
|
-
* Gets the protocol recipient address
|
|
24980
|
-
* @returns Promise<Address> - The protocol recipient address
|
|
24981
|
-
*/
|
|
24982
|
-
protocolRecipient() {
|
|
24983
|
-
return this.contract.read("protocolRecipient");
|
|
24984
|
-
}
|
|
24985
|
-
/**
|
|
24986
|
-
* Gets the total number of tokens managed by the revenue manager
|
|
24987
|
-
* @returns Promise<bigint> - The total count of tokens
|
|
24988
|
-
*/
|
|
24989
|
-
async tokensCount() {
|
|
24990
|
-
const nextInternalId = await this.contract.read("nextInternalId");
|
|
24991
|
-
return nextInternalId - 1n;
|
|
24992
|
-
}
|
|
24993
|
-
/**
|
|
24994
|
-
* Gets all tokens created by a specific creator address
|
|
24995
|
-
* @param creator - The address of the creator to query tokens for
|
|
24996
|
-
* @param sortByDesc - Optional boolean to sort tokens in descending order (default: false)
|
|
24997
|
-
* @returns Promise<Array<{flaunch: Address, tokenId: bigint}>> - Array of token objects containing flaunch address and token ID
|
|
24998
|
-
*/
|
|
24999
|
-
async allTokensByCreator(creator, sortByDesc = false) {
|
|
25000
|
-
const tokens = await this.contract.read("tokens", {
|
|
25001
|
-
_creator: creator,
|
|
25002
|
-
});
|
|
25003
|
-
if (sortByDesc) {
|
|
25004
|
-
return [...tokens].reverse();
|
|
25005
|
-
}
|
|
25006
|
-
return tokens;
|
|
25007
|
-
}
|
|
25008
|
-
/**
|
|
25009
|
-
* Gets all tokens currently managed by the revenue manager contract
|
|
25010
|
-
* @dev Uses multicall to batch requests for better performance
|
|
25011
|
-
* @param sortByDesc - Optional boolean to sort tokens in descending order (default: false)
|
|
25012
|
-
* @returns Promise<Array<{flaunch: Address, tokenId: bigint}>> - Array of token objects containing flaunch address and token ID
|
|
25013
|
-
*/
|
|
25014
|
-
async allTokensInManager(sortByDesc = false) {
|
|
25015
|
-
const count = await this.tokensCount();
|
|
25016
|
-
const multicall = new ReadMulticall(this.drift);
|
|
25017
|
-
let calldatas = Array.from({ length: Number(count) }, (_, i) => this.contract.encodeFunctionData("internalIds", {
|
|
25018
|
-
_internalId: BigInt(i + 1),
|
|
25019
|
-
}));
|
|
25020
|
-
// Reverse the array if sortByDesc is true
|
|
25021
|
-
if (sortByDesc) {
|
|
25022
|
-
calldatas = calldatas.reverse();
|
|
25023
|
-
}
|
|
25024
|
-
const result = await multicall.aggregate3(calldatas.map((calldata) => ({
|
|
25025
|
-
target: this.contract.address,
|
|
25026
|
-
callData: calldata,
|
|
25027
|
-
})));
|
|
25028
|
-
return result.map((r) => this.contract.decodeFunctionReturn("internalIds", r.returnData));
|
|
25029
|
-
}
|
|
25030
|
-
}
|
|
25031
|
-
class ReadWriteRevenueManager extends ReadRevenueManager {
|
|
25032
|
-
constructor(address, drift$1 = drift.createDrift()) {
|
|
25033
|
-
super(address, drift$1);
|
|
25034
|
-
}
|
|
25035
|
-
/**
|
|
25036
|
-
* Allows the protocol recipient to claim the protocol's share of the revenue
|
|
25037
|
-
* @returns Promise<TransactionResponse> - The transaction response
|
|
25038
|
-
*/
|
|
25039
|
-
protocolClaim() {
|
|
25040
|
-
return this.contract.write("claim", {});
|
|
25041
|
-
}
|
|
25042
|
-
/**
|
|
25043
|
-
* Allows the creator to claim their total share of the revenue from a revenue manager
|
|
25044
|
-
* @returns Promise<TransactionResponse> - The transaction response
|
|
25045
|
-
*/
|
|
25046
|
-
creatorClaim() {
|
|
25047
|
-
return this.contract.write("claim", {});
|
|
25048
|
-
}
|
|
25049
|
-
/**
|
|
25050
|
-
* Allows the creator to claim their share of the revenue from specific flaunch tokens
|
|
25051
|
-
* @param flaunchTokens - The flaunch token ids to claim the revenue for
|
|
25052
|
-
* @returns Promise<TransactionResponse> - The transaction response
|
|
25053
|
-
*/
|
|
25054
|
-
creatorClaimForTokens(flaunchTokens) {
|
|
25055
|
-
return this.contract.write("claim", {
|
|
25056
|
-
_flaunchToken: flaunchTokens,
|
|
25057
|
-
});
|
|
25058
|
-
}
|
|
25059
|
-
}
|
|
25060
|
-
|
|
25061
|
-
const TreasuryManagerAbi = [
|
|
25062
25141
|
{
|
|
25063
|
-
|
|
25064
|
-
name: "
|
|
25065
|
-
|
|
25142
|
+
inputs: [],
|
|
25143
|
+
name: "getCurrentBlockTimestamp",
|
|
25144
|
+
outputs: [
|
|
25066
25145
|
{
|
|
25067
|
-
|
|
25068
|
-
|
|
25069
|
-
|
|
25070
|
-
components: [
|
|
25071
|
-
{
|
|
25072
|
-
name: "flaunch",
|
|
25073
|
-
type: "address",
|
|
25074
|
-
internalType: "contract Flaunch",
|
|
25075
|
-
},
|
|
25076
|
-
{ name: "tokenId", type: "uint256", internalType: "uint256" },
|
|
25077
|
-
],
|
|
25146
|
+
internalType: "uint256",
|
|
25147
|
+
name: "timestamp",
|
|
25148
|
+
type: "uint256",
|
|
25078
25149
|
},
|
|
25079
|
-
{ name: "_creator", type: "address", internalType: "address" },
|
|
25080
|
-
{ name: "_data", type: "bytes", internalType: "bytes" },
|
|
25081
25150
|
],
|
|
25082
|
-
|
|
25083
|
-
|
|
25151
|
+
stateMutability: "view",
|
|
25152
|
+
type: "function",
|
|
25084
25153
|
},
|
|
25085
25154
|
{
|
|
25086
|
-
type: "function",
|
|
25087
|
-
name: "initialize",
|
|
25088
25155
|
inputs: [
|
|
25089
|
-
{
|
|
25090
|
-
|
|
25156
|
+
{
|
|
25157
|
+
internalType: "address",
|
|
25158
|
+
name: "addr",
|
|
25159
|
+
type: "address",
|
|
25160
|
+
},
|
|
25161
|
+
],
|
|
25162
|
+
name: "getEthBalance",
|
|
25163
|
+
outputs: [
|
|
25164
|
+
{
|
|
25165
|
+
internalType: "uint256",
|
|
25166
|
+
name: "balance",
|
|
25167
|
+
type: "uint256",
|
|
25168
|
+
},
|
|
25091
25169
|
],
|
|
25092
|
-
outputs: [],
|
|
25093
|
-
stateMutability: "nonpayable",
|
|
25094
|
-
},
|
|
25095
|
-
{
|
|
25096
|
-
type: "function",
|
|
25097
|
-
name: "managerOwner",
|
|
25098
|
-
inputs: [],
|
|
25099
|
-
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
25100
25170
|
stateMutability: "view",
|
|
25171
|
+
type: "function",
|
|
25101
25172
|
},
|
|
25102
25173
|
{
|
|
25103
|
-
type: "function",
|
|
25104
|
-
name: "permissions",
|
|
25105
25174
|
inputs: [],
|
|
25175
|
+
name: "getLastBlockHash",
|
|
25106
25176
|
outputs: [
|
|
25107
25177
|
{
|
|
25108
|
-
|
|
25109
|
-
|
|
25110
|
-
|
|
25178
|
+
internalType: "bytes32",
|
|
25179
|
+
name: "blockHash",
|
|
25180
|
+
type: "bytes32",
|
|
25111
25181
|
},
|
|
25112
25182
|
],
|
|
25113
25183
|
stateMutability: "view",
|
|
25184
|
+
type: "function",
|
|
25114
25185
|
},
|
|
25115
25186
|
{
|
|
25116
|
-
type: "function",
|
|
25117
|
-
name: "rescue",
|
|
25118
25187
|
inputs: [
|
|
25119
25188
|
{
|
|
25120
|
-
|
|
25121
|
-
|
|
25122
|
-
|
|
25189
|
+
internalType: "bool",
|
|
25190
|
+
name: "requireSuccess",
|
|
25191
|
+
type: "bool",
|
|
25192
|
+
},
|
|
25193
|
+
{
|
|
25123
25194
|
components: [
|
|
25124
25195
|
{
|
|
25125
|
-
|
|
25196
|
+
internalType: "address",
|
|
25197
|
+
name: "target",
|
|
25126
25198
|
type: "address",
|
|
25127
|
-
internalType: "contract Flaunch",
|
|
25128
25199
|
},
|
|
25129
|
-
{
|
|
25200
|
+
{
|
|
25201
|
+
internalType: "bytes",
|
|
25202
|
+
name: "callData",
|
|
25203
|
+
type: "bytes",
|
|
25204
|
+
},
|
|
25130
25205
|
],
|
|
25206
|
+
internalType: "struct Multicall3.Call[]",
|
|
25207
|
+
name: "calls",
|
|
25208
|
+
type: "tuple[]",
|
|
25131
25209
|
},
|
|
25132
|
-
{ name: "_recipient", type: "address", internalType: "address" },
|
|
25133
25210
|
],
|
|
25134
|
-
|
|
25135
|
-
|
|
25136
|
-
|
|
25137
|
-
|
|
25138
|
-
|
|
25139
|
-
|
|
25140
|
-
|
|
25141
|
-
|
|
25211
|
+
name: "tryAggregate",
|
|
25212
|
+
outputs: [
|
|
25213
|
+
{
|
|
25214
|
+
components: [
|
|
25215
|
+
{
|
|
25216
|
+
internalType: "bool",
|
|
25217
|
+
name: "success",
|
|
25218
|
+
type: "bool",
|
|
25219
|
+
},
|
|
25220
|
+
{
|
|
25221
|
+
internalType: "bytes",
|
|
25222
|
+
name: "returnData",
|
|
25223
|
+
type: "bytes",
|
|
25224
|
+
},
|
|
25225
|
+
],
|
|
25226
|
+
internalType: "struct Multicall3.Result[]",
|
|
25227
|
+
name: "returnData",
|
|
25228
|
+
type: "tuple[]",
|
|
25229
|
+
},
|
|
25142
25230
|
],
|
|
25143
|
-
|
|
25144
|
-
|
|
25231
|
+
stateMutability: "payable",
|
|
25232
|
+
type: "function",
|
|
25145
25233
|
},
|
|
25146
25234
|
{
|
|
25147
|
-
type: "function",
|
|
25148
|
-
name: "transferManagerOwnership",
|
|
25149
25235
|
inputs: [
|
|
25150
25236
|
{
|
|
25151
|
-
|
|
25152
|
-
|
|
25153
|
-
|
|
25237
|
+
internalType: "bool",
|
|
25238
|
+
name: "requireSuccess",
|
|
25239
|
+
type: "bool",
|
|
25240
|
+
},
|
|
25241
|
+
{
|
|
25242
|
+
components: [
|
|
25243
|
+
{
|
|
25244
|
+
internalType: "address",
|
|
25245
|
+
name: "target",
|
|
25246
|
+
type: "address",
|
|
25247
|
+
},
|
|
25248
|
+
{
|
|
25249
|
+
internalType: "bytes",
|
|
25250
|
+
name: "callData",
|
|
25251
|
+
type: "bytes",
|
|
25252
|
+
},
|
|
25253
|
+
],
|
|
25254
|
+
internalType: "struct Multicall3.Call[]",
|
|
25255
|
+
name: "calls",
|
|
25256
|
+
type: "tuple[]",
|
|
25154
25257
|
},
|
|
25155
25258
|
],
|
|
25156
|
-
|
|
25157
|
-
|
|
25158
|
-
|
|
25159
|
-
|
|
25160
|
-
|
|
25161
|
-
|
|
25162
|
-
|
|
25163
|
-
|
|
25164
|
-
|
|
25165
|
-
|
|
25166
|
-
|
|
25167
|
-
|
|
25168
|
-
|
|
25169
|
-
|
|
25170
|
-
|
|
25171
|
-
|
|
25172
|
-
|
|
25173
|
-
|
|
25174
|
-
|
|
25175
|
-
|
|
25176
|
-
|
|
25177
|
-
|
|
25178
|
-
|
|
25179
|
-
|
|
25180
|
-
|
|
25181
|
-
|
|
25182
|
-
|
|
25183
|
-
|
|
25184
|
-
|
|
25185
|
-
|
|
25186
|
-
|
|
25187
|
-
|
|
25188
|
-
|
|
25189
|
-
|
|
25190
|
-
|
|
25191
|
-
|
|
25192
|
-
|
|
25193
|
-
|
|
25194
|
-
|
|
25195
|
-
|
|
25196
|
-
|
|
25197
|
-
|
|
25198
|
-
|
|
25199
|
-
*/
|
|
25200
|
-
class ReadWriteTreasuryManager extends ReadTreasuryManager {
|
|
25201
|
-
constructor(address, drift$1 = drift.createDrift()) {
|
|
25202
|
-
super(address, drift$1);
|
|
25203
|
-
}
|
|
25204
|
-
/**
|
|
25205
|
-
* Deposits a flaunch token to the treasury
|
|
25206
|
-
* @param flaunchToken - The flaunch token to deposit
|
|
25207
|
-
* @param creator - The address of the creator
|
|
25208
|
-
* @param data - Additional data for the deposit
|
|
25209
|
-
* @returns Promise<void>
|
|
25210
|
-
*/
|
|
25211
|
-
deposit(flaunchToken, creator, data) {
|
|
25212
|
-
return this.contract.write("deposit", {
|
|
25213
|
-
_flaunchToken: flaunchToken,
|
|
25214
|
-
_creator: creator,
|
|
25215
|
-
_data: data,
|
|
25216
|
-
});
|
|
25217
|
-
}
|
|
25218
|
-
/**
|
|
25219
|
-
* Sets the permissions contract address
|
|
25220
|
-
* @param permissions - The address of the new permissions contract
|
|
25221
|
-
* @returns Promise<void>
|
|
25222
|
-
*/
|
|
25223
|
-
setPermissions(permissions) {
|
|
25224
|
-
return this.contract.write("setPermissions", {
|
|
25225
|
-
_permissions: permissions,
|
|
25226
|
-
});
|
|
25227
|
-
}
|
|
25228
|
-
/**
|
|
25229
|
-
* Transfers the manager ownership to a new address
|
|
25230
|
-
* @param newManagerOwner - The address of the new manager owner
|
|
25231
|
-
* @returns Promise<void>
|
|
25232
|
-
*/
|
|
25233
|
-
transferManagerOwnership(newManagerOwner) {
|
|
25234
|
-
return this.contract.write("transferManagerOwnership", {
|
|
25235
|
-
_newManagerOwner: newManagerOwner,
|
|
25236
|
-
});
|
|
25237
|
-
}
|
|
25238
|
-
}
|
|
25239
|
-
|
|
25240
|
-
// our min/max tick range that is valid for the tick spacing (60)
|
|
25241
|
-
const TickFinder = {
|
|
25242
|
-
MIN_TICK: -887220,
|
|
25243
|
-
MAX_TICK: 887220,
|
|
25244
|
-
};
|
|
25245
|
-
const Q96 = 2n ** 96n;
|
|
25246
|
-
const Q192 = 2n ** 192n;
|
|
25247
|
-
const TICK_SPACING = 60;
|
|
25248
|
-
const getPoolId = (poolKey) => {
|
|
25249
|
-
// Pack the data in the same order as Solidity struct
|
|
25250
|
-
const packed = viem.concat([
|
|
25251
|
-
viem.pad(poolKey.currency0, { size: 32 }), // address padded to 32 bytes
|
|
25252
|
-
viem.pad(poolKey.currency1, { size: 32 }), // address padded to 32 bytes
|
|
25253
|
-
viem.pad(viem.toHex(poolKey.fee), { size: 32 }), // uint24 padded to 32 bytes
|
|
25254
|
-
viem.pad(viem.toHex(poolKey.tickSpacing), { size: 32 }), // int24 padded to 32 bytes
|
|
25255
|
-
viem.pad(poolKey.hooks, { size: 32 }), // address padded to 32 bytes
|
|
25256
|
-
]);
|
|
25257
|
-
return viem.keccak256(packed);
|
|
25258
|
-
};
|
|
25259
|
-
const orderPoolKey = (poolKey) => {
|
|
25260
|
-
const [currency0, currency1] = poolKey.currency0 < poolKey.currency1
|
|
25261
|
-
? [poolKey.currency0, poolKey.currency1]
|
|
25262
|
-
: [poolKey.currency1, poolKey.currency0];
|
|
25263
|
-
return {
|
|
25264
|
-
...poolKey,
|
|
25265
|
-
currency0,
|
|
25266
|
-
currency1,
|
|
25267
|
-
};
|
|
25268
|
-
};
|
|
25269
|
-
const getValidTick = ({ tick, tickSpacing, roundDown = true, }) => {
|
|
25270
|
-
// If the tick is already valid, exit early
|
|
25271
|
-
if (tick % tickSpacing === 0) {
|
|
25272
|
-
return tick;
|
|
25273
|
-
}
|
|
25274
|
-
// Division that rounds towards zero (like Solidity)
|
|
25275
|
-
let validTick = Math.trunc(tick / tickSpacing) * tickSpacing;
|
|
25276
|
-
// Handle negative ticks (Solidity behavior)
|
|
25277
|
-
if (tick < 0 && tick % tickSpacing !== 0) {
|
|
25278
|
-
validTick -= tickSpacing;
|
|
25279
|
-
}
|
|
25280
|
-
// If not rounding down, add TICK_SPACING to get the upper tick
|
|
25281
|
-
if (!roundDown) {
|
|
25282
|
-
validTick += tickSpacing;
|
|
25283
|
-
}
|
|
25284
|
-
return validTick;
|
|
25285
|
-
};
|
|
25286
|
-
// Rounds up or down to the nearest tick
|
|
25287
|
-
const getNearestUsableTick = ({ tick, tickSpacing, }) => {
|
|
25288
|
-
const rounded = Math.round(tick / tickSpacing) * tickSpacing;
|
|
25289
|
-
return Math.max(TickFinder.MIN_TICK, Math.min(TickFinder.MAX_TICK, rounded));
|
|
25290
|
-
};
|
|
25291
|
-
const getAmount0ForLiquidity = (sqrtRatioAX96, sqrtRatioBX96, liquidity) => {
|
|
25292
|
-
let [sqrtRatioA, sqrtRatioB] = [sqrtRatioAX96, sqrtRatioBX96];
|
|
25293
|
-
if (sqrtRatioA > sqrtRatioB) {
|
|
25294
|
-
[sqrtRatioA, sqrtRatioB] = [sqrtRatioB, sqrtRatioA];
|
|
25295
|
-
}
|
|
25296
|
-
const leftShiftedLiquidity = liquidity << 96n;
|
|
25297
|
-
const sqrtDiff = sqrtRatioB - sqrtRatioA;
|
|
25298
|
-
const multipliedRes = leftShiftedLiquidity * sqrtDiff;
|
|
25299
|
-
const numerator = multipliedRes / sqrtRatioB;
|
|
25300
|
-
const amount0 = numerator / sqrtRatioA;
|
|
25301
|
-
return amount0;
|
|
25302
|
-
};
|
|
25303
|
-
const getAmount1ForLiquidity = (sqrtRatioAX96, sqrtRatioBX96, liquidity) => {
|
|
25304
|
-
let [sqrtRatioA, sqrtRatioB] = [sqrtRatioAX96, sqrtRatioBX96];
|
|
25305
|
-
if (sqrtRatioA > sqrtRatioB) {
|
|
25306
|
-
[sqrtRatioA, sqrtRatioB] = [sqrtRatioB, sqrtRatioA];
|
|
25307
|
-
}
|
|
25308
|
-
const sqrtDiff = sqrtRatioB - sqrtRatioA;
|
|
25309
|
-
const multipliedRes = liquidity * sqrtDiff;
|
|
25310
|
-
const amount1 = multipliedRes / 2n ** 96n;
|
|
25311
|
-
return amount1;
|
|
25312
|
-
};
|
|
25313
|
-
const getSqrtPriceX96FromTick = (tick) => {
|
|
25314
|
-
const absTick = tick < 0 ? BigInt(-tick) : BigInt(tick);
|
|
25315
|
-
if (absTick > TickFinder.MAX_TICK) {
|
|
25316
|
-
throw new Error("Tick out of range");
|
|
25259
|
+
name: "tryBlockAndAggregate",
|
|
25260
|
+
outputs: [
|
|
25261
|
+
{
|
|
25262
|
+
internalType: "uint256",
|
|
25263
|
+
name: "blockNumber",
|
|
25264
|
+
type: "uint256",
|
|
25265
|
+
},
|
|
25266
|
+
{
|
|
25267
|
+
internalType: "bytes32",
|
|
25268
|
+
name: "blockHash",
|
|
25269
|
+
type: "bytes32",
|
|
25270
|
+
},
|
|
25271
|
+
{
|
|
25272
|
+
components: [
|
|
25273
|
+
{
|
|
25274
|
+
internalType: "bool",
|
|
25275
|
+
name: "success",
|
|
25276
|
+
type: "bool",
|
|
25277
|
+
},
|
|
25278
|
+
{
|
|
25279
|
+
internalType: "bytes",
|
|
25280
|
+
name: "returnData",
|
|
25281
|
+
type: "bytes",
|
|
25282
|
+
},
|
|
25283
|
+
],
|
|
25284
|
+
internalType: "struct Multicall3.Result[]",
|
|
25285
|
+
name: "returnData",
|
|
25286
|
+
type: "tuple[]",
|
|
25287
|
+
},
|
|
25288
|
+
],
|
|
25289
|
+
stateMutability: "payable",
|
|
25290
|
+
type: "function",
|
|
25291
|
+
},
|
|
25292
|
+
];
|
|
25293
|
+
|
|
25294
|
+
class ReadMulticall {
|
|
25295
|
+
constructor(drift) {
|
|
25296
|
+
// same address across all chains
|
|
25297
|
+
this.address = "0xcA11bde05977b3631167028862bE2a173976CA11";
|
|
25298
|
+
this.contract = drift.contract({
|
|
25299
|
+
abi: MulticallAbi,
|
|
25300
|
+
address: this.address,
|
|
25301
|
+
});
|
|
25317
25302
|
}
|
|
25318
|
-
|
|
25319
|
-
|
|
25320
|
-
|
|
25321
|
-
|
|
25322
|
-
|
|
25323
|
-
|
|
25324
|
-
|
|
25325
|
-
|
|
25326
|
-
ratio = (ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0n) >> 128n;
|
|
25327
|
-
if ((absTick & 16n) !== 0n)
|
|
25328
|
-
ratio = (ratio * 0xffcb9843d60f6159c9db58835c926644n) >> 128n;
|
|
25329
|
-
if ((absTick & 32n) !== 0n)
|
|
25330
|
-
ratio = (ratio * 0xff973b41fa98c081472e6896dfb254c0n) >> 128n;
|
|
25331
|
-
if ((absTick & 64n) !== 0n)
|
|
25332
|
-
ratio = (ratio * 0xff2ea16466c96a3843ec78b326b52861n) >> 128n;
|
|
25333
|
-
if ((absTick & 128n) !== 0n)
|
|
25334
|
-
ratio = (ratio * 0xfe5dee046a99a2a811c461f1969c3053n) >> 128n;
|
|
25335
|
-
if ((absTick & 256n) !== 0n)
|
|
25336
|
-
ratio = (ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4n) >> 128n;
|
|
25337
|
-
if ((absTick & 512n) !== 0n)
|
|
25338
|
-
ratio = (ratio * 0xf987a7253ac413176f2b074cf7815e54n) >> 128n;
|
|
25339
|
-
if ((absTick & 1024n) !== 0n)
|
|
25340
|
-
ratio = (ratio * 0xf3392b0822b70005940c7a398e4b70f3n) >> 128n;
|
|
25341
|
-
if ((absTick & 2048n) !== 0n)
|
|
25342
|
-
ratio = (ratio * 0xe7159475a2c29b7443b29c7fa6e889d9n) >> 128n;
|
|
25343
|
-
if ((absTick & 4096n) !== 0n)
|
|
25344
|
-
ratio = (ratio * 0xd097f3bdfd2022b8845ad8f792aa5825n) >> 128n;
|
|
25345
|
-
if ((absTick & 8192n) !== 0n)
|
|
25346
|
-
ratio = (ratio * 0xa9f746462d870fdf8a65dc1f90e061e5n) >> 128n;
|
|
25347
|
-
if ((absTick & 16384n) !== 0n)
|
|
25348
|
-
ratio = (ratio * 0x70d869a156d2a1b890bb3df62baf32f7n) >> 128n;
|
|
25349
|
-
if ((absTick & 32768n) !== 0n)
|
|
25350
|
-
ratio = (ratio * 0x31be135f97d08fd981231505542fcfa6n) >> 128n;
|
|
25351
|
-
if ((absTick & 65536n) !== 0n)
|
|
25352
|
-
ratio = (ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9n) >> 128n;
|
|
25353
|
-
if ((absTick & 131072n) !== 0n)
|
|
25354
|
-
ratio = (ratio * 0x5d6af8dedb81196699c329225ee604n) >> 128n;
|
|
25355
|
-
if ((absTick & 262144n) !== 0n)
|
|
25356
|
-
ratio = (ratio * 0x2216e584f5fa1ea926041bedfe98n) >> 128n;
|
|
25357
|
-
if ((absTick & 524288n) !== 0n)
|
|
25358
|
-
ratio = (ratio * 0x48a170391f7dc42444e8fa2n) >> 128n;
|
|
25359
|
-
if (tick > 0) {
|
|
25360
|
-
ratio = (2n ** 256n - 1n) / ratio;
|
|
25303
|
+
aggregate3(calls) {
|
|
25304
|
+
return this.contract.simulateWrite("aggregate3", {
|
|
25305
|
+
calls: calls.map((call) => ({
|
|
25306
|
+
target: call.target,
|
|
25307
|
+
allowFailure: true,
|
|
25308
|
+
callData: call.callData,
|
|
25309
|
+
})),
|
|
25310
|
+
});
|
|
25361
25311
|
}
|
|
25362
|
-
|
|
25363
|
-
|
|
25364
|
-
|
|
25365
|
-
|
|
25312
|
+
}
|
|
25313
|
+
|
|
25314
|
+
class ReadRevenueManager {
|
|
25315
|
+
constructor(address, drift$1 = drift.createDrift()) {
|
|
25316
|
+
this.drift = drift$1;
|
|
25317
|
+
this.contract = drift$1.contract({
|
|
25318
|
+
abi: RevenueManagerAbi,
|
|
25319
|
+
address,
|
|
25320
|
+
});
|
|
25366
25321
|
}
|
|
25367
|
-
|
|
25368
|
-
|
|
25369
|
-
|
|
25370
|
-
|
|
25371
|
-
|
|
25372
|
-
|
|
25373
|
-
|
|
25374
|
-
|
|
25375
|
-
|
|
25376
|
-
// Current price is below the position range
|
|
25377
|
-
amount0 = getAmount0ForLiquidity(sqrtPriceLowerX96, sqrtPriceUpperX96, liquidity);
|
|
25322
|
+
/**
|
|
25323
|
+
* Gets the claimable balance of ETH for the recipient
|
|
25324
|
+
* @param recipient - The address of the recipient to check
|
|
25325
|
+
* @returns Promise<bigint> - The claimable balance of ETH
|
|
25326
|
+
*/
|
|
25327
|
+
balances(address) {
|
|
25328
|
+
return this.contract.read("balances", {
|
|
25329
|
+
_recipient: address,
|
|
25330
|
+
});
|
|
25378
25331
|
}
|
|
25379
|
-
|
|
25380
|
-
|
|
25381
|
-
|
|
25382
|
-
|
|
25332
|
+
/**
|
|
25333
|
+
* Gets the protocol recipient address
|
|
25334
|
+
* @returns Promise<Address> - The protocol recipient address
|
|
25335
|
+
*/
|
|
25336
|
+
protocolRecipient() {
|
|
25337
|
+
return this.contract.read("protocolRecipient");
|
|
25383
25338
|
}
|
|
25384
|
-
|
|
25385
|
-
|
|
25386
|
-
|
|
25339
|
+
/**
|
|
25340
|
+
* Gets the total number of tokens managed by the revenue manager
|
|
25341
|
+
* @returns Promise<bigint> - The total count of tokens
|
|
25342
|
+
*/
|
|
25343
|
+
async tokensCount() {
|
|
25344
|
+
const nextInternalId = await this.contract.read("nextInternalId");
|
|
25345
|
+
return nextInternalId - 1n;
|
|
25387
25346
|
}
|
|
25388
|
-
|
|
25389
|
-
|
|
25390
|
-
|
|
25391
|
-
|
|
25392
|
-
|
|
25393
|
-
|
|
25394
|
-
|
|
25395
|
-
|
|
25396
|
-
|
|
25397
|
-
|
|
25398
|
-
|
|
25399
|
-
|
|
25400
|
-
// Input is token1 per token0 (e.g., memecoin per flETH)
|
|
25401
|
-
// Convert from human-readable to raw: divide by (10^decimals0 / 10^decimals1)
|
|
25402
|
-
priceRatio = inputPrice / Math.pow(10, decimals0 - decimals1);
|
|
25403
|
-
}
|
|
25404
|
-
else {
|
|
25405
|
-
// Input is token0 per token1 (e.g., flETH per memecoin)
|
|
25406
|
-
// Invert to get token1 per token0, then convert to raw
|
|
25407
|
-
priceRatio = 1 / inputPrice / Math.pow(10, decimals0 - decimals1);
|
|
25408
|
-
}
|
|
25409
|
-
// Calculate tick: tick = log(price) / log(1.0001)
|
|
25410
|
-
const tick = Math.log(priceRatio) / Math.log(1.0001);
|
|
25411
|
-
if (shouldGetNearestUsableTick) {
|
|
25412
|
-
return getValidTick({
|
|
25413
|
-
tick: Math.round(tick),
|
|
25414
|
-
tickSpacing: spacing,
|
|
25415
|
-
});
|
|
25416
|
-
}
|
|
25417
|
-
else {
|
|
25418
|
-
return Math.round(tick);
|
|
25347
|
+
/**
|
|
25348
|
+
* Gets all tokens created by a specific creator address
|
|
25349
|
+
* @param creator - The address of the creator to query tokens for
|
|
25350
|
+
* @param sortByDesc - Optional boolean to sort tokens in descending order (default: false)
|
|
25351
|
+
* @returns Promise<Array<{flaunch: Address, tokenId: bigint}>> - Array of token objects containing flaunch address and token ID
|
|
25352
|
+
*/
|
|
25353
|
+
async allTokensByCreator(creator, sortByDesc = false) {
|
|
25354
|
+
const tokens = await this.contract.read("tokens", {
|
|
25355
|
+
_creator: creator,
|
|
25356
|
+
});
|
|
25357
|
+
if (sortByDesc) {
|
|
25358
|
+
return [...tokens].reverse();
|
|
25419
25359
|
}
|
|
25360
|
+
return tokens;
|
|
25420
25361
|
}
|
|
25421
|
-
|
|
25422
|
-
|
|
25423
|
-
|
|
25424
|
-
|
|
25425
|
-
|
|
25426
|
-
|
|
25427
|
-
|
|
25428
|
-
|
|
25429
|
-
|
|
25430
|
-
}
|
|
25431
|
-
|
|
25432
|
-
|
|
25362
|
+
/**
|
|
25363
|
+
* Gets all tokens currently managed by the revenue manager contract
|
|
25364
|
+
* @dev Uses multicall to batch requests for better performance
|
|
25365
|
+
* @param sortByDesc - Optional boolean to sort tokens in descending order (default: false)
|
|
25366
|
+
* @returns Promise<Array<{flaunch: Address, tokenId: bigint}>> - Array of token objects containing flaunch address and token ID
|
|
25367
|
+
*/
|
|
25368
|
+
async allTokensInManager(sortByDesc = false) {
|
|
25369
|
+
const count = await this.tokensCount();
|
|
25370
|
+
const multicall = new ReadMulticall(this.drift);
|
|
25371
|
+
let calldatas = Array.from({ length: Number(count) }, (_, i) => this.contract.encodeFunctionData("internalIds", {
|
|
25372
|
+
_internalId: BigInt(i + 1),
|
|
25373
|
+
}));
|
|
25374
|
+
// Reverse the array if sortByDesc is true
|
|
25375
|
+
if (sortByDesc) {
|
|
25376
|
+
calldatas = calldatas.reverse();
|
|
25433
25377
|
}
|
|
25378
|
+
const result = await multicall.aggregate3(calldatas.map((calldata) => ({
|
|
25379
|
+
target: this.contract.address,
|
|
25380
|
+
callData: calldata,
|
|
25381
|
+
})));
|
|
25382
|
+
return result.map((r) => this.contract.decodeFunctionReturn("internalIds", r.returnData));
|
|
25434
25383
|
}
|
|
25435
|
-
}
|
|
25436
|
-
|
|
25437
|
-
|
|
25438
|
-
|
|
25439
|
-
const getLiquidityFromAmounts = (params) => {
|
|
25440
|
-
const sqrtRatioCurrentX96 = getSqrtPriceX96FromTick(params.currentTick);
|
|
25441
|
-
let sqrtRatioAX96 = getSqrtPriceX96FromTick(params.tickLower);
|
|
25442
|
-
let sqrtRatioBX96 = getSqrtPriceX96FromTick(params.tickUpper);
|
|
25443
|
-
if (sqrtRatioAX96 > sqrtRatioBX96) {
|
|
25444
|
-
[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
|
|
25445
|
-
}
|
|
25446
|
-
if (sqrtRatioCurrentX96 <= sqrtRatioAX96) {
|
|
25447
|
-
return maxLiquidityForAmount0Precise(sqrtRatioAX96, sqrtRatioBX96, params.amount0);
|
|
25448
|
-
}
|
|
25449
|
-
else if (sqrtRatioCurrentX96 < sqrtRatioBX96) {
|
|
25450
|
-
const liquidity0 = maxLiquidityForAmount0Precise(sqrtRatioCurrentX96, sqrtRatioBX96, params.amount0);
|
|
25451
|
-
const liquidity1 = maxLiquidityForAmount1(sqrtRatioAX96, sqrtRatioCurrentX96, params.amount1);
|
|
25452
|
-
return liquidity0 < liquidity1 ? liquidity0 : liquidity1;
|
|
25453
|
-
}
|
|
25454
|
-
else {
|
|
25455
|
-
return maxLiquidityForAmount1(sqrtRatioAX96, sqrtRatioBX96, params.amount1);
|
|
25384
|
+
}
|
|
25385
|
+
class ReadWriteRevenueManager extends ReadRevenueManager {
|
|
25386
|
+
constructor(address, drift$1 = drift.createDrift()) {
|
|
25387
|
+
super(address, drift$1);
|
|
25456
25388
|
}
|
|
25457
|
-
|
|
25458
|
-
|
|
25459
|
-
|
|
25460
|
-
|
|
25461
|
-
|
|
25462
|
-
|
|
25463
|
-
* @param amount0 The token0 amount
|
|
25464
|
-
* @returns liquidity for amount0, precise
|
|
25465
|
-
*/
|
|
25466
|
-
function maxLiquidityForAmount0Precise(sqrtRatioAX96, sqrtRatioBX96, amount0) {
|
|
25467
|
-
if (sqrtRatioAX96 > sqrtRatioBX96) {
|
|
25468
|
-
[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
|
|
25389
|
+
/**
|
|
25390
|
+
* Allows the protocol recipient to claim the protocol's share of the revenue
|
|
25391
|
+
* @returns Promise<TransactionResponse> - The transaction response
|
|
25392
|
+
*/
|
|
25393
|
+
protocolClaim() {
|
|
25394
|
+
return this.contract.write("claim", {});
|
|
25469
25395
|
}
|
|
25470
|
-
|
|
25471
|
-
|
|
25472
|
-
|
|
25396
|
+
/**
|
|
25397
|
+
* Allows the creator to claim their total share of the revenue from a revenue manager
|
|
25398
|
+
* @returns Promise<TransactionResponse> - The transaction response
|
|
25399
|
+
*/
|
|
25400
|
+
creatorClaim() {
|
|
25401
|
+
return this.contract.write("claim", {});
|
|
25402
|
+
}
|
|
25403
|
+
/**
|
|
25404
|
+
* Allows the creator to claim their share of the revenue from specific flaunch tokens
|
|
25405
|
+
* @param flaunchTokens - The flaunch token ids to claim the revenue for
|
|
25406
|
+
* @returns Promise<TransactionResponse> - The transaction response
|
|
25407
|
+
*/
|
|
25408
|
+
creatorClaimForTokens(flaunchTokens) {
|
|
25409
|
+
return this.contract.write("claim", {
|
|
25410
|
+
_flaunchToken: flaunchTokens,
|
|
25411
|
+
});
|
|
25473
25412
|
}
|
|
25474
|
-
const Q96 = 2n ** 96n;
|
|
25475
|
-
const numerator = amount0 * sqrtRatioAX96 * sqrtRatioBX96;
|
|
25476
|
-
const denominator = Q96 * (sqrtRatioBX96 - sqrtRatioAX96);
|
|
25477
|
-
return numerator / denominator;
|
|
25478
25413
|
}
|
|
25414
|
+
|
|
25415
|
+
const TreasuryManagerAbi = [
|
|
25416
|
+
{
|
|
25417
|
+
type: "function",
|
|
25418
|
+
name: "deposit",
|
|
25419
|
+
inputs: [
|
|
25420
|
+
{
|
|
25421
|
+
name: "_flaunchToken",
|
|
25422
|
+
type: "tuple",
|
|
25423
|
+
internalType: "struct ITreasuryManager.FlaunchToken",
|
|
25424
|
+
components: [
|
|
25425
|
+
{
|
|
25426
|
+
name: "flaunch",
|
|
25427
|
+
type: "address",
|
|
25428
|
+
internalType: "contract Flaunch",
|
|
25429
|
+
},
|
|
25430
|
+
{ name: "tokenId", type: "uint256", internalType: "uint256" },
|
|
25431
|
+
],
|
|
25432
|
+
},
|
|
25433
|
+
{ name: "_creator", type: "address", internalType: "address" },
|
|
25434
|
+
{ name: "_data", type: "bytes", internalType: "bytes" },
|
|
25435
|
+
],
|
|
25436
|
+
outputs: [],
|
|
25437
|
+
stateMutability: "nonpayable",
|
|
25438
|
+
},
|
|
25439
|
+
{
|
|
25440
|
+
type: "function",
|
|
25441
|
+
name: "initialize",
|
|
25442
|
+
inputs: [
|
|
25443
|
+
{ name: "_owner", type: "address", internalType: "address" },
|
|
25444
|
+
{ name: "_data", type: "bytes", internalType: "bytes" },
|
|
25445
|
+
],
|
|
25446
|
+
outputs: [],
|
|
25447
|
+
stateMutability: "nonpayable",
|
|
25448
|
+
},
|
|
25449
|
+
{
|
|
25450
|
+
type: "function",
|
|
25451
|
+
name: "managerOwner",
|
|
25452
|
+
inputs: [],
|
|
25453
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
25454
|
+
stateMutability: "view",
|
|
25455
|
+
},
|
|
25456
|
+
{
|
|
25457
|
+
type: "function",
|
|
25458
|
+
name: "permissions",
|
|
25459
|
+
inputs: [],
|
|
25460
|
+
outputs: [
|
|
25461
|
+
{
|
|
25462
|
+
name: "",
|
|
25463
|
+
type: "address",
|
|
25464
|
+
internalType: "contract IManagerPermissions",
|
|
25465
|
+
},
|
|
25466
|
+
],
|
|
25467
|
+
stateMutability: "view",
|
|
25468
|
+
},
|
|
25469
|
+
{
|
|
25470
|
+
type: "function",
|
|
25471
|
+
name: "rescue",
|
|
25472
|
+
inputs: [
|
|
25473
|
+
{
|
|
25474
|
+
name: "_flaunchToken",
|
|
25475
|
+
type: "tuple",
|
|
25476
|
+
internalType: "struct ITreasuryManager.FlaunchToken",
|
|
25477
|
+
components: [
|
|
25478
|
+
{
|
|
25479
|
+
name: "flaunch",
|
|
25480
|
+
type: "address",
|
|
25481
|
+
internalType: "contract Flaunch",
|
|
25482
|
+
},
|
|
25483
|
+
{ name: "tokenId", type: "uint256", internalType: "uint256" },
|
|
25484
|
+
],
|
|
25485
|
+
},
|
|
25486
|
+
{ name: "_recipient", type: "address", internalType: "address" },
|
|
25487
|
+
],
|
|
25488
|
+
outputs: [],
|
|
25489
|
+
stateMutability: "nonpayable",
|
|
25490
|
+
},
|
|
25491
|
+
{
|
|
25492
|
+
type: "function",
|
|
25493
|
+
name: "setPermissions",
|
|
25494
|
+
inputs: [
|
|
25495
|
+
{ name: "_permissions", type: "address", internalType: "address" },
|
|
25496
|
+
],
|
|
25497
|
+
outputs: [],
|
|
25498
|
+
stateMutability: "nonpayable",
|
|
25499
|
+
},
|
|
25500
|
+
{
|
|
25501
|
+
type: "function",
|
|
25502
|
+
name: "transferManagerOwnership",
|
|
25503
|
+
inputs: [
|
|
25504
|
+
{
|
|
25505
|
+
name: "_newManagerOwner",
|
|
25506
|
+
type: "address",
|
|
25507
|
+
internalType: "address",
|
|
25508
|
+
},
|
|
25509
|
+
],
|
|
25510
|
+
outputs: [],
|
|
25511
|
+
stateMutability: "nonpayable",
|
|
25512
|
+
},
|
|
25513
|
+
];
|
|
25514
|
+
|
|
25479
25515
|
/**
|
|
25480
|
-
*
|
|
25481
|
-
*
|
|
25482
|
-
* @param sqrtRatioBX96 The price at the upper tick boundary
|
|
25483
|
-
* @param amount1 The token1 amount
|
|
25484
|
-
* @returns liquidity for amount1
|
|
25516
|
+
* Client for interacting with the TreasuryManager contract in read-only mode
|
|
25517
|
+
* Provides methods to query permissions and manager owner
|
|
25485
25518
|
*/
|
|
25486
|
-
|
|
25487
|
-
|
|
25488
|
-
|
|
25519
|
+
class ReadTreasuryManager {
|
|
25520
|
+
/**
|
|
25521
|
+
* Creates a new ReadTreasuryManager instance
|
|
25522
|
+
* @param address - The address of the TreasuryManager contract
|
|
25523
|
+
* @param drift - Optional drift instance for contract interactions (creates new instance if not provided)
|
|
25524
|
+
* @throws Error if address is not provided
|
|
25525
|
+
*/
|
|
25526
|
+
constructor(address, drift$1 = drift.createDrift()) {
|
|
25527
|
+
if (!address) {
|
|
25528
|
+
throw new Error("Address is required");
|
|
25529
|
+
}
|
|
25530
|
+
this.contract = drift$1.contract({
|
|
25531
|
+
abi: TreasuryManagerAbi,
|
|
25532
|
+
address,
|
|
25533
|
+
});
|
|
25489
25534
|
}
|
|
25490
|
-
|
|
25491
|
-
|
|
25492
|
-
|
|
25535
|
+
/**
|
|
25536
|
+
* Gets the permissions contract address
|
|
25537
|
+
* @returns Promise<Address> - The address of the permissions contract
|
|
25538
|
+
*/
|
|
25539
|
+
permissions() {
|
|
25540
|
+
return this.contract.read("permissions");
|
|
25541
|
+
}
|
|
25542
|
+
/**
|
|
25543
|
+
* Gets the manager owner address
|
|
25544
|
+
* @returns Promise<Address> - The address of the manager owner
|
|
25545
|
+
*/
|
|
25546
|
+
managerOwner() {
|
|
25547
|
+
return this.contract.read("managerOwner");
|
|
25493
25548
|
}
|
|
25494
|
-
const Q96 = 2n ** 96n;
|
|
25495
|
-
return (amount1 * Q96) / (sqrtRatioBX96 - sqrtRatioAX96);
|
|
25496
25549
|
}
|
|
25497
25550
|
/**
|
|
25498
|
-
*
|
|
25499
|
-
*
|
|
25551
|
+
* Extended client for interacting with the TreasuryManager contract with write capabilities
|
|
25552
|
+
* Provides methods to deposit tokens, set permissions, and transfer ownership
|
|
25500
25553
|
*/
|
|
25501
|
-
|
|
25502
|
-
|
|
25503
|
-
|
|
25504
|
-
return { amount0: 0n, amount1: 0n };
|
|
25505
|
-
}
|
|
25506
|
-
const sqrtRatioCurrentX96 = getSqrtPriceX96FromTick(params.currentTick);
|
|
25507
|
-
let sqrtRatioAX96 = getSqrtPriceX96FromTick(params.tickLower);
|
|
25508
|
-
let sqrtRatioBX96 = getSqrtPriceX96FromTick(params.tickUpper);
|
|
25509
|
-
if (sqrtRatioAX96 > sqrtRatioBX96) {
|
|
25510
|
-
[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
|
|
25554
|
+
class ReadWriteTreasuryManager extends ReadTreasuryManager {
|
|
25555
|
+
constructor(address, drift$1 = drift.createDrift()) {
|
|
25556
|
+
super(address, drift$1);
|
|
25511
25557
|
}
|
|
25512
|
-
|
|
25513
|
-
|
|
25514
|
-
|
|
25515
|
-
|
|
25516
|
-
|
|
25558
|
+
/**
|
|
25559
|
+
* Deposits a flaunch token to the treasury
|
|
25560
|
+
* @param flaunchToken - The flaunch token to deposit
|
|
25561
|
+
* @param creator - The address of the creator
|
|
25562
|
+
* @param data - Additional data for the deposit
|
|
25563
|
+
* @returns Promise<void>
|
|
25564
|
+
*/
|
|
25565
|
+
deposit(flaunchToken, creator, data) {
|
|
25566
|
+
return this.contract.write("deposit", {
|
|
25567
|
+
_flaunchToken: flaunchToken,
|
|
25568
|
+
_creator: creator,
|
|
25569
|
+
_data: data,
|
|
25570
|
+
});
|
|
25517
25571
|
}
|
|
25518
|
-
|
|
25519
|
-
|
|
25520
|
-
|
|
25521
|
-
|
|
25572
|
+
/**
|
|
25573
|
+
* Sets the permissions contract address
|
|
25574
|
+
* @param permissions - The address of the new permissions contract
|
|
25575
|
+
* @returns Promise<void>
|
|
25576
|
+
*/
|
|
25577
|
+
setPermissions(permissions) {
|
|
25578
|
+
return this.contract.write("setPermissions", {
|
|
25579
|
+
_permissions: permissions,
|
|
25580
|
+
});
|
|
25522
25581
|
}
|
|
25523
|
-
|
|
25524
|
-
|
|
25525
|
-
|
|
25582
|
+
/**
|
|
25583
|
+
* Transfers the manager ownership to a new address
|
|
25584
|
+
* @param newManagerOwner - The address of the new manager owner
|
|
25585
|
+
* @returns Promise<void>
|
|
25586
|
+
*/
|
|
25587
|
+
transferManagerOwnership(newManagerOwner) {
|
|
25588
|
+
return this.contract.write("transferManagerOwnership", {
|
|
25589
|
+
_newManagerOwner: newManagerOwner,
|
|
25590
|
+
});
|
|
25526
25591
|
}
|
|
25527
|
-
|
|
25528
|
-
};
|
|
25592
|
+
}
|
|
25529
25593
|
|
|
25530
25594
|
const chainIdToChain = {
|
|
25531
25595
|
[base.id]: base,
|
|
@@ -26352,6 +26416,50 @@ class ReadFlaunchSDK {
|
|
|
26352
26416
|
}
|
|
26353
26417
|
return poll();
|
|
26354
26418
|
}
|
|
26419
|
+
/**
|
|
26420
|
+
* Parses a transaction to extract PoolCreated event data
|
|
26421
|
+
* @param txHash - The transaction hash to parse
|
|
26422
|
+
* @returns PoolCreated event parameters or null if not found
|
|
26423
|
+
*/
|
|
26424
|
+
async getPoolCreatedFromTx(txHash) {
|
|
26425
|
+
if (!this.publicClient) {
|
|
26426
|
+
throw new Error("Public client is required to fetch transaction data");
|
|
26427
|
+
}
|
|
26428
|
+
// Get transaction receipt
|
|
26429
|
+
const receipt = await this.publicClient.getTransactionReceipt({
|
|
26430
|
+
hash: txHash,
|
|
26431
|
+
});
|
|
26432
|
+
if (!receipt) {
|
|
26433
|
+
throw new Error(`Transaction not found: ${txHash}`);
|
|
26434
|
+
}
|
|
26435
|
+
// Find PoolCreated event in logs by trying to decode each log
|
|
26436
|
+
// Using V1_2 ABI which is compatible with all versions (V1_2 has extra fields that are optional)
|
|
26437
|
+
for (const log of receipt.logs) {
|
|
26438
|
+
try {
|
|
26439
|
+
const decodedLog = viem.decodeEventLog({
|
|
26440
|
+
abi: FlaunchPositionManagerV1_2Abi,
|
|
26441
|
+
data: log.data,
|
|
26442
|
+
topics: log.topics,
|
|
26443
|
+
});
|
|
26444
|
+
if (decodedLog.eventName === "PoolCreated") {
|
|
26445
|
+
return {
|
|
26446
|
+
poolId: decodedLog.args._poolId,
|
|
26447
|
+
memecoin: decodedLog.args._memecoin,
|
|
26448
|
+
memecoinTreasury: decodedLog.args._memecoinTreasury,
|
|
26449
|
+
tokenId: decodedLog.args._tokenId,
|
|
26450
|
+
currencyFlipped: decodedLog.args._currencyFlipped,
|
|
26451
|
+
flaunchFee: decodedLog.args._flaunchFee,
|
|
26452
|
+
params: decodedLog.args._params,
|
|
26453
|
+
};
|
|
26454
|
+
}
|
|
26455
|
+
}
|
|
26456
|
+
catch (error) {
|
|
26457
|
+
// Not a PoolCreated event or decoding failed, continue to next log
|
|
26458
|
+
continue;
|
|
26459
|
+
}
|
|
26460
|
+
}
|
|
26461
|
+
return null;
|
|
26462
|
+
}
|
|
26355
26463
|
/**
|
|
26356
26464
|
* Watches for pool swap events
|
|
26357
26465
|
* @param params - Parameters for watching pool swaps including optional coin filter
|
|
@@ -27373,6 +27481,25 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
|
|
|
27373
27481
|
const hash = await this.readWriteFlaunchZap.deployStakingManager(params);
|
|
27374
27482
|
return await this.readWriteTreasuryManagerFactory.getManagerDeployedAddressFromTx(hash);
|
|
27375
27483
|
}
|
|
27484
|
+
/**
|
|
27485
|
+
* Deploys a new BuyBack manager
|
|
27486
|
+
* @param params - Parameters for deploying the BuyBack manager
|
|
27487
|
+
* @param params.managerOwner - The address of the manager owner
|
|
27488
|
+
* @param params.creatorSharePercent - The % share that a creator will earn from their token (0-100)
|
|
27489
|
+
* @param params.ownerSharePercent - The % share that the manager owner will earn from their token (0-100)
|
|
27490
|
+
* @param params.buyBackPoolKey - The Uniswap V4 pool key configuration for the buyback pool
|
|
27491
|
+
* @param params.buyBackPoolKey.currency0 - The lower currency of the pool (sorted numerically)
|
|
27492
|
+
* @param params.buyBackPoolKey.currency1 - The higher currency of the pool (sorted numerically)
|
|
27493
|
+
* @param params.buyBackPoolKey.fee - The pool LP fee, capped at 1_000_000
|
|
27494
|
+
* @param params.buyBackPoolKey.tickSpacing - Tick spacing for the pool
|
|
27495
|
+
* @param params.buyBackPoolKey.hooks - The hooks address of the pool
|
|
27496
|
+
* @param params.permissions - The permissions for the BuyBack manager
|
|
27497
|
+
* @returns Address of the deployed BuyBack manager
|
|
27498
|
+
*/
|
|
27499
|
+
async deployBuyBackManager(params) {
|
|
27500
|
+
const hash = await this.readWriteFlaunchZap.deployBuyBackManager(params);
|
|
27501
|
+
return await this.readWriteTreasuryManagerFactory.getManagerDeployedAddressFromTx(hash);
|
|
27502
|
+
}
|
|
27376
27503
|
/**
|
|
27377
27504
|
* Creates a new Flaunch on the specified version
|
|
27378
27505
|
* @param params - Parameters for creating the Flaunch
|
|
@@ -32016,6 +32143,7 @@ exports.BidWallAddress = BidWallAddress;
|
|
|
32016
32143
|
exports.BidWallV1_1Abi = BidWallV1_1Abi;
|
|
32017
32144
|
exports.BidWallV1_1Address = BidWallV1_1Address;
|
|
32018
32145
|
exports.BidwallAbi = BidwallAbi;
|
|
32146
|
+
exports.BuyBackManagerAddress = BuyBackManagerAddress;
|
|
32019
32147
|
exports.ClankerWorldVerifierAddress = ClankerWorldVerifierAddress;
|
|
32020
32148
|
exports.ClosedPermissionsAddress = ClosedPermissionsAddress;
|
|
32021
32149
|
exports.DopplerVerifierAddress = DopplerVerifierAddress;
|