@flaunch/sdk 0.9.8-beta.0 → 0.9.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/addresses/index.cjs +5 -5
- package/dist/addresses/index.cjs.map +1 -1
- package/dist/addresses/index.js +5 -5
- package/dist/addresses/index.js.map +1 -1
- package/dist/addresses.d.ts +1 -1
- 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/clients/TokenImporter.d.ts.map +1 -1
- package/dist/helpers/index.cjs +0 -1
- package/dist/helpers/index.cjs.map +1 -1
- package/dist/helpers/index.js +0 -1
- package/dist/helpers/index.js.map +1 -1
- package/dist/index.cjs.js +1049 -973
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +1050 -974
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/dist/sdk/FlaunchSDK.d.ts +17 -1
- package/dist/sdk/FlaunchSDK.d.ts.map +1 -1
- package/dist/types.d.ts +1 -2
- 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",
|
|
@@ -5786,10 +5790,6 @@ const ZoraVerifierAddress = {
|
|
|
5786
5790
|
[base.id]: "0x656047fd43d2c3a121f2ef859d7171d7dd59f8b9",
|
|
5787
5791
|
[baseSepolia.id]: "0x05a5763e9199b88bb591c6b112d0424b2cd7a99e",
|
|
5788
5792
|
};
|
|
5789
|
-
const SolanaVerifierAddress = {
|
|
5790
|
-
[base.id]: "0x0000000000000000000000000000000000000000",
|
|
5791
|
-
[baseSepolia.id]: "0x47226918E518f205584bd75Bf81E0b532B0B3Ea7",
|
|
5792
|
-
};
|
|
5793
5793
|
/** ======== */
|
|
5794
5794
|
/** Permissions */
|
|
5795
5795
|
const ClosedPermissionsAddress = {
|
|
@@ -11897,7 +11897,6 @@ exports.Verifier = void 0;
|
|
|
11897
11897
|
Verifier["VIRTUALS"] = "virtuals";
|
|
11898
11898
|
Verifier["WHITELIST"] = "whitelist";
|
|
11899
11899
|
Verifier["ZORA"] = "zora";
|
|
11900
|
-
Verifier["SOLANA"] = "solana";
|
|
11901
11900
|
})(exports.Verifier || (exports.Verifier = {}));
|
|
11902
11901
|
exports.LiquidityMode = void 0;
|
|
11903
11902
|
(function (LiquidityMode) {
|
|
@@ -13782,194 +13781,484 @@ class ReadWriteFlaunchPositionManagerV1_1 extends ReadFlaunchPositionManagerV1_1
|
|
|
13782
13781
|
}
|
|
13783
13782
|
}
|
|
13784
13783
|
|
|
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
|
-
|
|
13815
|
-
|
|
13816
|
-
|
|
13817
|
-
|
|
13818
|
-
});
|
|
13819
|
-
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;
|
|
13820
13817
|
}
|
|
13821
|
-
|
|
13822
|
-
|
|
13823
|
-
|
|
13824
|
-
|
|
13825
|
-
|
|
13826
|
-
amount: flaunchingFee,
|
|
13827
|
-
slippage: (params.slippagePercent ?? 0 / 100).toFixed(18).toString(),
|
|
13828
|
-
swapType: "EXACT_OUT",
|
|
13829
|
-
});
|
|
13830
|
-
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;
|
|
13831
13823
|
}
|
|
13832
|
-
|
|
13833
|
-
|
|
13834
|
-
|
|
13835
|
-
ethRequiredToFlaunch(params) {
|
|
13836
|
-
return this.contract.read("calculateFee", {
|
|
13837
|
-
_premineAmount: params.premineAmount ?? 0n,
|
|
13838
|
-
_slippage: params.slippagePercent
|
|
13839
|
-
? BigInt(params.slippagePercent * 100)
|
|
13840
|
-
: 0n,
|
|
13841
|
-
_initialPriceParams: params.initialPriceParams,
|
|
13842
|
-
});
|
|
13824
|
+
// If not rounding down, add TICK_SPACING to get the upper tick
|
|
13825
|
+
if (!roundDown) {
|
|
13826
|
+
validTick += tickSpacing;
|
|
13843
13827
|
}
|
|
13844
|
-
|
|
13845
|
-
|
|
13846
|
-
|
|
13847
|
-
|
|
13848
|
-
|
|
13849
|
-
|
|
13850
|
-
|
|
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];
|
|
13851
13839
|
}
|
|
13852
|
-
|
|
13853
|
-
|
|
13854
|
-
|
|
13855
|
-
|
|
13856
|
-
|
|
13857
|
-
|
|
13858
|
-
|
|
13859
|
-
|
|
13860
|
-
|
|
13861
|
-
|
|
13862
|
-
|
|
13863
|
-
], [initialMCapInUSDCWei]);
|
|
13864
|
-
const fairLaunchInBps = BigInt(params.fairLaunchPercent * 100);
|
|
13865
|
-
const creatorFeeAllocationInBps = params.creatorFeeAllocationPercent * 100;
|
|
13866
|
-
const ethRequired = await this.ethRequiredToFlaunch({
|
|
13867
|
-
premineAmount: params.premineAmount ?? 0n,
|
|
13868
|
-
initialPriceParams,
|
|
13869
|
-
slippagePercent: 5,
|
|
13870
|
-
});
|
|
13871
|
-
const _treasuryManagerParams = params.treasuryManagerParams
|
|
13872
|
-
? {
|
|
13873
|
-
manager: params.treasuryManagerParams.manager ?? viem.zeroAddress,
|
|
13874
|
-
permissions: params.treasuryManagerParams.permissions ?? exports.Permissions.OPEN,
|
|
13875
|
-
initializeData: params.treasuryManagerParams.initializeData ?? "0x",
|
|
13876
|
-
depositData: params.treasuryManagerParams.depositData ?? "0x",
|
|
13877
|
-
}
|
|
13878
|
-
: {
|
|
13879
|
-
manager: viem.zeroAddress,
|
|
13880
|
-
permissions: exports.Permissions.OPEN,
|
|
13881
|
-
initializeData: "0x",
|
|
13882
|
-
depositData: "0x",
|
|
13883
|
-
};
|
|
13884
|
-
const feeCalculatorParams = params.trustedSignerSettings
|
|
13885
|
-
? viem.encodeAbiParameters([
|
|
13886
|
-
{ type: "bool", name: "enabled" },
|
|
13887
|
-
{ type: "uint256", name: "walletCap" },
|
|
13888
|
-
{ type: "uint256", name: "txCap" },
|
|
13889
|
-
], [
|
|
13890
|
-
params.trustedSignerSettings.enabled,
|
|
13891
|
-
params.trustedSignerSettings.walletCap ?? 0n,
|
|
13892
|
-
params.trustedSignerSettings.txCap ?? 0n,
|
|
13893
|
-
])
|
|
13894
|
-
: "0x";
|
|
13895
|
-
const _premineSwapHookData = params.trustedSignerSettings?.enabled
|
|
13896
|
-
? viem.encodeAbiParameters([
|
|
13897
|
-
{ type: "address", name: "referrer" },
|
|
13898
|
-
{
|
|
13899
|
-
type: "tuple",
|
|
13900
|
-
components: [
|
|
13901
|
-
{ type: "uint256", name: "deadline" },
|
|
13902
|
-
{ type: "bytes", name: "signature" },
|
|
13903
|
-
],
|
|
13904
|
-
},
|
|
13905
|
-
], [
|
|
13906
|
-
viem.zeroAddress,
|
|
13907
|
-
{
|
|
13908
|
-
deadline: BigInt(params.trustedSignerSettings.premineSignedMessage?.deadline ?? 0),
|
|
13909
|
-
signature: params.trustedSignerSettings.premineSignedMessage?.signature ??
|
|
13910
|
-
"0x",
|
|
13911
|
-
},
|
|
13912
|
-
])
|
|
13913
|
-
: "0x";
|
|
13914
|
-
return this.contract.write("flaunch", {
|
|
13915
|
-
_flaunchParams: {
|
|
13916
|
-
name: params.name,
|
|
13917
|
-
symbol: params.symbol,
|
|
13918
|
-
tokenUri: params.tokenUri,
|
|
13919
|
-
initialTokenFairLaunch: (this.TOTAL_SUPPLY * fairLaunchInBps) / 10000n,
|
|
13920
|
-
fairLaunchDuration: BigInt(params.fairLaunchDuration),
|
|
13921
|
-
premineAmount: params.premineAmount ?? 0n,
|
|
13922
|
-
creator: params.creator,
|
|
13923
|
-
creatorFeeAllocation: creatorFeeAllocationInBps,
|
|
13924
|
-
flaunchAt: params.flaunchAt ?? 0n,
|
|
13925
|
-
initialPriceParams,
|
|
13926
|
-
feeCalculatorParams,
|
|
13927
|
-
},
|
|
13928
|
-
_trustedFeeSigner: params.trustedSignerSettings?.trustedFeeSigner ?? viem.zeroAddress,
|
|
13929
|
-
_premineSwapHookData,
|
|
13930
|
-
_treasuryManagerParams: {
|
|
13931
|
-
..._treasuryManagerParams,
|
|
13932
|
-
permissions: getPermissionsAddress(_treasuryManagerParams.permissions, this.chainId),
|
|
13933
|
-
},
|
|
13934
|
-
_whitelistParams: {
|
|
13935
|
-
merkleRoot: viem.zeroHash,
|
|
13936
|
-
merkleIPFSHash: "",
|
|
13937
|
-
maxTokens: 0n,
|
|
13938
|
-
},
|
|
13939
|
-
_airdropParams: {
|
|
13940
|
-
airdropIndex: 0n,
|
|
13941
|
-
airdropAmount: 0n,
|
|
13942
|
-
airdropEndTime: 0n,
|
|
13943
|
-
merkleRoot: viem.zeroHash,
|
|
13944
|
-
merkleIPFSHash: "",
|
|
13945
|
-
},
|
|
13946
|
-
}, {
|
|
13947
|
-
value: ethRequired,
|
|
13948
|
-
});
|
|
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];
|
|
13949
13851
|
}
|
|
13950
|
-
|
|
13951
|
-
|
|
13952
|
-
|
|
13953
|
-
|
|
13954
|
-
|
|
13955
|
-
|
|
13956
|
-
|
|
13957
|
-
|
|
13958
|
-
|
|
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");
|
|
13959
13861
|
}
|
|
13960
|
-
|
|
13961
|
-
|
|
13962
|
-
|
|
13963
|
-
|
|
13964
|
-
|
|
13965
|
-
|
|
13966
|
-
|
|
13967
|
-
|
|
13968
|
-
|
|
13969
|
-
|
|
13970
|
-
|
|
13971
|
-
|
|
13972
|
-
|
|
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)
|
|
13973
14262
|
* @param params.flaunchAt - Optional timestamp when the flaunch should start
|
|
13974
14263
|
* @param params.premineAmount - Optional amount of tokens to premine
|
|
13975
14264
|
* @returns Transaction response for the flaunch creation
|
|
@@ -14147,11 +14436,71 @@ class ReadWriteFlaunchZap extends ReadFlaunchZap {
|
|
|
14147
14436
|
},
|
|
14148
14437
|
], [
|
|
14149
14438
|
{
|
|
14150
|
-
stakingToken: params.stakingToken,
|
|
14151
|
-
minEscrowDuration: params.minEscrowDuration,
|
|
14152
|
-
minStakeDuration: params.minStakeDuration,
|
|
14439
|
+
stakingToken: params.stakingToken,
|
|
14440
|
+
minEscrowDuration: params.minEscrowDuration,
|
|
14441
|
+
minStakeDuration: params.minStakeDuration,
|
|
14442
|
+
creatorShare: (BigInt(params.creatorSharePercent) * VALID_SHARE_TOTAL) / 100n,
|
|
14443
|
+
ownerShare: (BigInt(params.ownerSharePercent) * VALID_SHARE_TOTAL) / 100n,
|
|
14444
|
+
},
|
|
14445
|
+
]),
|
|
14446
|
+
_permissions: permissionsAddress,
|
|
14447
|
+
});
|
|
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
|
+
{
|
|
14153
14495
|
creatorShare: (BigInt(params.creatorSharePercent) * VALID_SHARE_TOTAL) / 100n,
|
|
14154
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
|
+
}),
|
|
14155
14504
|
},
|
|
14156
14505
|
]),
|
|
14157
14506
|
_permissions: permissionsAddress,
|
|
@@ -20368,8 +20717,6 @@ class ReadTokenImporter {
|
|
|
20368
20717
|
return WhitelistVerifierAddress[this.chainId];
|
|
20369
20718
|
case exports.Verifier.ZORA:
|
|
20370
20719
|
return ZoraVerifierAddress[this.chainId];
|
|
20371
|
-
case exports.Verifier.SOLANA:
|
|
20372
|
-
return SolanaVerifierAddress[this.chainId];
|
|
20373
20720
|
default:
|
|
20374
20721
|
throw new Error(`Unknown verifier: ${verifier}`);
|
|
20375
20722
|
}
|
|
@@ -24640,257 +24987,9 @@ const MulticallAbi = [
|
|
|
24640
24987
|
],
|
|
24641
24988
|
stateMutability: "payable",
|
|
24642
24989
|
type: "function",
|
|
24643
|
-
},
|
|
24644
|
-
{
|
|
24645
|
-
inputs: [
|
|
24646
|
-
{
|
|
24647
|
-
components: [
|
|
24648
|
-
{
|
|
24649
|
-
internalType: "address",
|
|
24650
|
-
name: "target",
|
|
24651
|
-
type: "address",
|
|
24652
|
-
},
|
|
24653
|
-
{
|
|
24654
|
-
internalType: "bytes",
|
|
24655
|
-
name: "callData",
|
|
24656
|
-
type: "bytes",
|
|
24657
|
-
},
|
|
24658
|
-
],
|
|
24659
|
-
internalType: "struct Multicall3.Call[]",
|
|
24660
|
-
name: "calls",
|
|
24661
|
-
type: "tuple[]",
|
|
24662
|
-
},
|
|
24663
|
-
],
|
|
24664
|
-
name: "blockAndAggregate",
|
|
24665
|
-
outputs: [
|
|
24666
|
-
{
|
|
24667
|
-
internalType: "uint256",
|
|
24668
|
-
name: "blockNumber",
|
|
24669
|
-
type: "uint256",
|
|
24670
|
-
},
|
|
24671
|
-
{
|
|
24672
|
-
internalType: "bytes32",
|
|
24673
|
-
name: "blockHash",
|
|
24674
|
-
type: "bytes32",
|
|
24675
|
-
},
|
|
24676
|
-
{
|
|
24677
|
-
components: [
|
|
24678
|
-
{
|
|
24679
|
-
internalType: "bool",
|
|
24680
|
-
name: "success",
|
|
24681
|
-
type: "bool",
|
|
24682
|
-
},
|
|
24683
|
-
{
|
|
24684
|
-
internalType: "bytes",
|
|
24685
|
-
name: "returnData",
|
|
24686
|
-
type: "bytes",
|
|
24687
|
-
},
|
|
24688
|
-
],
|
|
24689
|
-
internalType: "struct Multicall3.Result[]",
|
|
24690
|
-
name: "returnData",
|
|
24691
|
-
type: "tuple[]",
|
|
24692
|
-
},
|
|
24693
|
-
],
|
|
24694
|
-
stateMutability: "payable",
|
|
24695
|
-
type: "function",
|
|
24696
|
-
},
|
|
24697
|
-
{
|
|
24698
|
-
inputs: [],
|
|
24699
|
-
name: "getBasefee",
|
|
24700
|
-
outputs: [
|
|
24701
|
-
{
|
|
24702
|
-
internalType: "uint256",
|
|
24703
|
-
name: "basefee",
|
|
24704
|
-
type: "uint256",
|
|
24705
|
-
},
|
|
24706
|
-
],
|
|
24707
|
-
stateMutability: "view",
|
|
24708
|
-
type: "function",
|
|
24709
|
-
},
|
|
24710
|
-
{
|
|
24711
|
-
inputs: [
|
|
24712
|
-
{
|
|
24713
|
-
internalType: "uint256",
|
|
24714
|
-
name: "blockNumber",
|
|
24715
|
-
type: "uint256",
|
|
24716
|
-
},
|
|
24717
|
-
],
|
|
24718
|
-
name: "getBlockHash",
|
|
24719
|
-
outputs: [
|
|
24720
|
-
{
|
|
24721
|
-
internalType: "bytes32",
|
|
24722
|
-
name: "blockHash",
|
|
24723
|
-
type: "bytes32",
|
|
24724
|
-
},
|
|
24725
|
-
],
|
|
24726
|
-
stateMutability: "view",
|
|
24727
|
-
type: "function",
|
|
24728
|
-
},
|
|
24729
|
-
{
|
|
24730
|
-
inputs: [],
|
|
24731
|
-
name: "getBlockNumber",
|
|
24732
|
-
outputs: [
|
|
24733
|
-
{
|
|
24734
|
-
internalType: "uint256",
|
|
24735
|
-
name: "blockNumber",
|
|
24736
|
-
type: "uint256",
|
|
24737
|
-
},
|
|
24738
|
-
],
|
|
24739
|
-
stateMutability: "view",
|
|
24740
|
-
type: "function",
|
|
24741
|
-
},
|
|
24742
|
-
{
|
|
24743
|
-
inputs: [],
|
|
24744
|
-
name: "getChainId",
|
|
24745
|
-
outputs: [
|
|
24746
|
-
{
|
|
24747
|
-
internalType: "uint256",
|
|
24748
|
-
name: "chainid",
|
|
24749
|
-
type: "uint256",
|
|
24750
|
-
},
|
|
24751
|
-
],
|
|
24752
|
-
stateMutability: "view",
|
|
24753
|
-
type: "function",
|
|
24754
|
-
},
|
|
24755
|
-
{
|
|
24756
|
-
inputs: [],
|
|
24757
|
-
name: "getCurrentBlockCoinbase",
|
|
24758
|
-
outputs: [
|
|
24759
|
-
{
|
|
24760
|
-
internalType: "address",
|
|
24761
|
-
name: "coinbase",
|
|
24762
|
-
type: "address",
|
|
24763
|
-
},
|
|
24764
|
-
],
|
|
24765
|
-
stateMutability: "view",
|
|
24766
|
-
type: "function",
|
|
24767
|
-
},
|
|
24768
|
-
{
|
|
24769
|
-
inputs: [],
|
|
24770
|
-
name: "getCurrentBlockDifficulty",
|
|
24771
|
-
outputs: [
|
|
24772
|
-
{
|
|
24773
|
-
internalType: "uint256",
|
|
24774
|
-
name: "difficulty",
|
|
24775
|
-
type: "uint256",
|
|
24776
|
-
},
|
|
24777
|
-
],
|
|
24778
|
-
stateMutability: "view",
|
|
24779
|
-
type: "function",
|
|
24780
|
-
},
|
|
24781
|
-
{
|
|
24782
|
-
inputs: [],
|
|
24783
|
-
name: "getCurrentBlockGasLimit",
|
|
24784
|
-
outputs: [
|
|
24785
|
-
{
|
|
24786
|
-
internalType: "uint256",
|
|
24787
|
-
name: "gaslimit",
|
|
24788
|
-
type: "uint256",
|
|
24789
|
-
},
|
|
24790
|
-
],
|
|
24791
|
-
stateMutability: "view",
|
|
24792
|
-
type: "function",
|
|
24793
|
-
},
|
|
24794
|
-
{
|
|
24795
|
-
inputs: [],
|
|
24796
|
-
name: "getCurrentBlockTimestamp",
|
|
24797
|
-
outputs: [
|
|
24798
|
-
{
|
|
24799
|
-
internalType: "uint256",
|
|
24800
|
-
name: "timestamp",
|
|
24801
|
-
type: "uint256",
|
|
24802
|
-
},
|
|
24803
|
-
],
|
|
24804
|
-
stateMutability: "view",
|
|
24805
|
-
type: "function",
|
|
24806
|
-
},
|
|
24807
|
-
{
|
|
24808
|
-
inputs: [
|
|
24809
|
-
{
|
|
24810
|
-
internalType: "address",
|
|
24811
|
-
name: "addr",
|
|
24812
|
-
type: "address",
|
|
24813
|
-
},
|
|
24814
|
-
],
|
|
24815
|
-
name: "getEthBalance",
|
|
24816
|
-
outputs: [
|
|
24817
|
-
{
|
|
24818
|
-
internalType: "uint256",
|
|
24819
|
-
name: "balance",
|
|
24820
|
-
type: "uint256",
|
|
24821
|
-
},
|
|
24822
|
-
],
|
|
24823
|
-
stateMutability: "view",
|
|
24824
|
-
type: "function",
|
|
24825
|
-
},
|
|
24826
|
-
{
|
|
24827
|
-
inputs: [],
|
|
24828
|
-
name: "getLastBlockHash",
|
|
24829
|
-
outputs: [
|
|
24830
|
-
{
|
|
24831
|
-
internalType: "bytes32",
|
|
24832
|
-
name: "blockHash",
|
|
24833
|
-
type: "bytes32",
|
|
24834
|
-
},
|
|
24835
|
-
],
|
|
24836
|
-
stateMutability: "view",
|
|
24837
|
-
type: "function",
|
|
24838
|
-
},
|
|
24839
|
-
{
|
|
24840
|
-
inputs: [
|
|
24841
|
-
{
|
|
24842
|
-
internalType: "bool",
|
|
24843
|
-
name: "requireSuccess",
|
|
24844
|
-
type: "bool",
|
|
24845
|
-
},
|
|
24846
|
-
{
|
|
24847
|
-
components: [
|
|
24848
|
-
{
|
|
24849
|
-
internalType: "address",
|
|
24850
|
-
name: "target",
|
|
24851
|
-
type: "address",
|
|
24852
|
-
},
|
|
24853
|
-
{
|
|
24854
|
-
internalType: "bytes",
|
|
24855
|
-
name: "callData",
|
|
24856
|
-
type: "bytes",
|
|
24857
|
-
},
|
|
24858
|
-
],
|
|
24859
|
-
internalType: "struct Multicall3.Call[]",
|
|
24860
|
-
name: "calls",
|
|
24861
|
-
type: "tuple[]",
|
|
24862
|
-
},
|
|
24863
|
-
],
|
|
24864
|
-
name: "tryAggregate",
|
|
24865
|
-
outputs: [
|
|
24866
|
-
{
|
|
24867
|
-
components: [
|
|
24868
|
-
{
|
|
24869
|
-
internalType: "bool",
|
|
24870
|
-
name: "success",
|
|
24871
|
-
type: "bool",
|
|
24872
|
-
},
|
|
24873
|
-
{
|
|
24874
|
-
internalType: "bytes",
|
|
24875
|
-
name: "returnData",
|
|
24876
|
-
type: "bytes",
|
|
24877
|
-
},
|
|
24878
|
-
],
|
|
24879
|
-
internalType: "struct Multicall3.Result[]",
|
|
24880
|
-
name: "returnData",
|
|
24881
|
-
type: "tuple[]",
|
|
24882
|
-
},
|
|
24883
|
-
],
|
|
24884
|
-
stateMutability: "payable",
|
|
24885
|
-
type: "function",
|
|
24886
|
-
},
|
|
24887
|
-
{
|
|
24888
|
-
inputs: [
|
|
24889
|
-
{
|
|
24890
|
-
internalType: "bool",
|
|
24891
|
-
name: "requireSuccess",
|
|
24892
|
-
type: "bool",
|
|
24893
|
-
},
|
|
24990
|
+
},
|
|
24991
|
+
{
|
|
24992
|
+
inputs: [
|
|
24894
24993
|
{
|
|
24895
24994
|
components: [
|
|
24896
24995
|
{
|
|
@@ -24909,7 +25008,7 @@ const MulticallAbi = [
|
|
|
24909
25008
|
type: "tuple[]",
|
|
24910
25009
|
},
|
|
24911
25010
|
],
|
|
24912
|
-
name: "
|
|
25011
|
+
name: "blockAndAggregate",
|
|
24913
25012
|
outputs: [
|
|
24914
25013
|
{
|
|
24915
25014
|
internalType: "uint256",
|
|
@@ -24942,597 +25041,555 @@ const MulticallAbi = [
|
|
|
24942
25041
|
stateMutability: "payable",
|
|
24943
25042
|
type: "function",
|
|
24944
25043
|
},
|
|
24945
|
-
];
|
|
24946
|
-
|
|
24947
|
-
class ReadMulticall {
|
|
24948
|
-
constructor(drift) {
|
|
24949
|
-
// same address across all chains
|
|
24950
|
-
this.address = "0xcA11bde05977b3631167028862bE2a173976CA11";
|
|
24951
|
-
this.contract = drift.contract({
|
|
24952
|
-
abi: MulticallAbi,
|
|
24953
|
-
address: this.address,
|
|
24954
|
-
});
|
|
24955
|
-
}
|
|
24956
|
-
aggregate3(calls) {
|
|
24957
|
-
return this.contract.simulateWrite("aggregate3", {
|
|
24958
|
-
calls: calls.map((call) => ({
|
|
24959
|
-
target: call.target,
|
|
24960
|
-
allowFailure: true,
|
|
24961
|
-
callData: call.callData,
|
|
24962
|
-
})),
|
|
24963
|
-
});
|
|
24964
|
-
}
|
|
24965
|
-
}
|
|
24966
|
-
|
|
24967
|
-
class ReadRevenueManager {
|
|
24968
|
-
constructor(address, drift$1 = drift.createDrift()) {
|
|
24969
|
-
this.drift = drift$1;
|
|
24970
|
-
this.contract = drift$1.contract({
|
|
24971
|
-
abi: RevenueManagerAbi,
|
|
24972
|
-
address,
|
|
24973
|
-
});
|
|
24974
|
-
}
|
|
24975
|
-
/**
|
|
24976
|
-
* Gets the claimable balance of ETH for the recipient
|
|
24977
|
-
* @param recipient - The address of the recipient to check
|
|
24978
|
-
* @returns Promise<bigint> - The claimable balance of ETH
|
|
24979
|
-
*/
|
|
24980
|
-
balances(address) {
|
|
24981
|
-
return this.contract.read("balances", {
|
|
24982
|
-
_recipient: address,
|
|
24983
|
-
});
|
|
24984
|
-
}
|
|
24985
|
-
/**
|
|
24986
|
-
* Gets the protocol recipient address
|
|
24987
|
-
* @returns Promise<Address> - The protocol recipient address
|
|
24988
|
-
*/
|
|
24989
|
-
protocolRecipient() {
|
|
24990
|
-
return this.contract.read("protocolRecipient");
|
|
24991
|
-
}
|
|
24992
|
-
/**
|
|
24993
|
-
* Gets the total number of tokens managed by the revenue manager
|
|
24994
|
-
* @returns Promise<bigint> - The total count of tokens
|
|
24995
|
-
*/
|
|
24996
|
-
async tokensCount() {
|
|
24997
|
-
const nextInternalId = await this.contract.read("nextInternalId");
|
|
24998
|
-
return nextInternalId - 1n;
|
|
24999
|
-
}
|
|
25000
|
-
/**
|
|
25001
|
-
* Gets all tokens created by a specific creator address
|
|
25002
|
-
* @param creator - The address of the creator to query tokens for
|
|
25003
|
-
* @param sortByDesc - Optional boolean to sort tokens in descending order (default: false)
|
|
25004
|
-
* @returns Promise<Array<{flaunch: Address, tokenId: bigint}>> - Array of token objects containing flaunch address and token ID
|
|
25005
|
-
*/
|
|
25006
|
-
async allTokensByCreator(creator, sortByDesc = false) {
|
|
25007
|
-
const tokens = await this.contract.read("tokens", {
|
|
25008
|
-
_creator: creator,
|
|
25009
|
-
});
|
|
25010
|
-
if (sortByDesc) {
|
|
25011
|
-
return [...tokens].reverse();
|
|
25012
|
-
}
|
|
25013
|
-
return tokens;
|
|
25014
|
-
}
|
|
25015
|
-
/**
|
|
25016
|
-
* Gets all tokens currently managed by the revenue manager contract
|
|
25017
|
-
* @dev Uses multicall to batch requests for better performance
|
|
25018
|
-
* @param sortByDesc - Optional boolean to sort tokens in descending order (default: false)
|
|
25019
|
-
* @returns Promise<Array<{flaunch: Address, tokenId: bigint}>> - Array of token objects containing flaunch address and token ID
|
|
25020
|
-
*/
|
|
25021
|
-
async allTokensInManager(sortByDesc = false) {
|
|
25022
|
-
const count = await this.tokensCount();
|
|
25023
|
-
const multicall = new ReadMulticall(this.drift);
|
|
25024
|
-
let calldatas = Array.from({ length: Number(count) }, (_, i) => this.contract.encodeFunctionData("internalIds", {
|
|
25025
|
-
_internalId: BigInt(i + 1),
|
|
25026
|
-
}));
|
|
25027
|
-
// Reverse the array if sortByDesc is true
|
|
25028
|
-
if (sortByDesc) {
|
|
25029
|
-
calldatas = calldatas.reverse();
|
|
25030
|
-
}
|
|
25031
|
-
const result = await multicall.aggregate3(calldatas.map((calldata) => ({
|
|
25032
|
-
target: this.contract.address,
|
|
25033
|
-
callData: calldata,
|
|
25034
|
-
})));
|
|
25035
|
-
return result.map((r) => this.contract.decodeFunctionReturn("internalIds", r.returnData));
|
|
25036
|
-
}
|
|
25037
|
-
}
|
|
25038
|
-
class ReadWriteRevenueManager extends ReadRevenueManager {
|
|
25039
|
-
constructor(address, drift$1 = drift.createDrift()) {
|
|
25040
|
-
super(address, drift$1);
|
|
25041
|
-
}
|
|
25042
|
-
/**
|
|
25043
|
-
* Allows the protocol recipient to claim the protocol's share of the revenue
|
|
25044
|
-
* @returns Promise<TransactionResponse> - The transaction response
|
|
25045
|
-
*/
|
|
25046
|
-
protocolClaim() {
|
|
25047
|
-
return this.contract.write("claim", {});
|
|
25048
|
-
}
|
|
25049
|
-
/**
|
|
25050
|
-
* Allows the creator to claim their total share of the revenue from a revenue manager
|
|
25051
|
-
* @returns Promise<TransactionResponse> - The transaction response
|
|
25052
|
-
*/
|
|
25053
|
-
creatorClaim() {
|
|
25054
|
-
return this.contract.write("claim", {});
|
|
25055
|
-
}
|
|
25056
|
-
/**
|
|
25057
|
-
* Allows the creator to claim their share of the revenue from specific flaunch tokens
|
|
25058
|
-
* @param flaunchTokens - The flaunch token ids to claim the revenue for
|
|
25059
|
-
* @returns Promise<TransactionResponse> - The transaction response
|
|
25060
|
-
*/
|
|
25061
|
-
creatorClaimForTokens(flaunchTokens) {
|
|
25062
|
-
return this.contract.write("claim", {
|
|
25063
|
-
_flaunchToken: flaunchTokens,
|
|
25064
|
-
});
|
|
25065
|
-
}
|
|
25066
|
-
}
|
|
25067
|
-
|
|
25068
|
-
const TreasuryManagerAbi = [
|
|
25069
25044
|
{
|
|
25045
|
+
inputs: [],
|
|
25046
|
+
name: "getBasefee",
|
|
25047
|
+
outputs: [
|
|
25048
|
+
{
|
|
25049
|
+
internalType: "uint256",
|
|
25050
|
+
name: "basefee",
|
|
25051
|
+
type: "uint256",
|
|
25052
|
+
},
|
|
25053
|
+
],
|
|
25054
|
+
stateMutability: "view",
|
|
25070
25055
|
type: "function",
|
|
25071
|
-
|
|
25056
|
+
},
|
|
25057
|
+
{
|
|
25072
25058
|
inputs: [
|
|
25073
25059
|
{
|
|
25074
|
-
|
|
25075
|
-
|
|
25076
|
-
|
|
25077
|
-
components: [
|
|
25078
|
-
{
|
|
25079
|
-
name: "flaunch",
|
|
25080
|
-
type: "address",
|
|
25081
|
-
internalType: "contract Flaunch",
|
|
25082
|
-
},
|
|
25083
|
-
{ name: "tokenId", type: "uint256", internalType: "uint256" },
|
|
25084
|
-
],
|
|
25060
|
+
internalType: "uint256",
|
|
25061
|
+
name: "blockNumber",
|
|
25062
|
+
type: "uint256",
|
|
25085
25063
|
},
|
|
25086
|
-
{ name: "_creator", type: "address", internalType: "address" },
|
|
25087
|
-
{ name: "_data", type: "bytes", internalType: "bytes" },
|
|
25088
25064
|
],
|
|
25089
|
-
|
|
25090
|
-
|
|
25065
|
+
name: "getBlockHash",
|
|
25066
|
+
outputs: [
|
|
25067
|
+
{
|
|
25068
|
+
internalType: "bytes32",
|
|
25069
|
+
name: "blockHash",
|
|
25070
|
+
type: "bytes32",
|
|
25071
|
+
},
|
|
25072
|
+
],
|
|
25073
|
+
stateMutability: "view",
|
|
25074
|
+
type: "function",
|
|
25091
25075
|
},
|
|
25092
25076
|
{
|
|
25077
|
+
inputs: [],
|
|
25078
|
+
name: "getBlockNumber",
|
|
25079
|
+
outputs: [
|
|
25080
|
+
{
|
|
25081
|
+
internalType: "uint256",
|
|
25082
|
+
name: "blockNumber",
|
|
25083
|
+
type: "uint256",
|
|
25084
|
+
},
|
|
25085
|
+
],
|
|
25086
|
+
stateMutability: "view",
|
|
25093
25087
|
type: "function",
|
|
25094
|
-
|
|
25088
|
+
},
|
|
25089
|
+
{
|
|
25090
|
+
inputs: [],
|
|
25091
|
+
name: "getChainId",
|
|
25092
|
+
outputs: [
|
|
25093
|
+
{
|
|
25094
|
+
internalType: "uint256",
|
|
25095
|
+
name: "chainid",
|
|
25096
|
+
type: "uint256",
|
|
25097
|
+
},
|
|
25098
|
+
],
|
|
25099
|
+
stateMutability: "view",
|
|
25100
|
+
type: "function",
|
|
25101
|
+
},
|
|
25102
|
+
{
|
|
25103
|
+
inputs: [],
|
|
25104
|
+
name: "getCurrentBlockCoinbase",
|
|
25105
|
+
outputs: [
|
|
25106
|
+
{
|
|
25107
|
+
internalType: "address",
|
|
25108
|
+
name: "coinbase",
|
|
25109
|
+
type: "address",
|
|
25110
|
+
},
|
|
25111
|
+
],
|
|
25112
|
+
stateMutability: "view",
|
|
25113
|
+
type: "function",
|
|
25114
|
+
},
|
|
25115
|
+
{
|
|
25116
|
+
inputs: [],
|
|
25117
|
+
name: "getCurrentBlockDifficulty",
|
|
25118
|
+
outputs: [
|
|
25119
|
+
{
|
|
25120
|
+
internalType: "uint256",
|
|
25121
|
+
name: "difficulty",
|
|
25122
|
+
type: "uint256",
|
|
25123
|
+
},
|
|
25124
|
+
],
|
|
25125
|
+
stateMutability: "view",
|
|
25126
|
+
type: "function",
|
|
25127
|
+
},
|
|
25128
|
+
{
|
|
25129
|
+
inputs: [],
|
|
25130
|
+
name: "getCurrentBlockGasLimit",
|
|
25131
|
+
outputs: [
|
|
25132
|
+
{
|
|
25133
|
+
internalType: "uint256",
|
|
25134
|
+
name: "gaslimit",
|
|
25135
|
+
type: "uint256",
|
|
25136
|
+
},
|
|
25137
|
+
],
|
|
25138
|
+
stateMutability: "view",
|
|
25139
|
+
type: "function",
|
|
25140
|
+
},
|
|
25141
|
+
{
|
|
25142
|
+
inputs: [],
|
|
25143
|
+
name: "getCurrentBlockTimestamp",
|
|
25144
|
+
outputs: [
|
|
25145
|
+
{
|
|
25146
|
+
internalType: "uint256",
|
|
25147
|
+
name: "timestamp",
|
|
25148
|
+
type: "uint256",
|
|
25149
|
+
},
|
|
25150
|
+
],
|
|
25151
|
+
stateMutability: "view",
|
|
25152
|
+
type: "function",
|
|
25153
|
+
},
|
|
25154
|
+
{
|
|
25095
25155
|
inputs: [
|
|
25096
|
-
{
|
|
25097
|
-
|
|
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
|
+
},
|
|
25098
25169
|
],
|
|
25099
|
-
outputs: [],
|
|
25100
|
-
stateMutability: "nonpayable",
|
|
25101
|
-
},
|
|
25102
|
-
{
|
|
25103
|
-
type: "function",
|
|
25104
|
-
name: "managerOwner",
|
|
25105
|
-
inputs: [],
|
|
25106
|
-
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
25107
25170
|
stateMutability: "view",
|
|
25171
|
+
type: "function",
|
|
25108
25172
|
},
|
|
25109
25173
|
{
|
|
25110
|
-
type: "function",
|
|
25111
|
-
name: "permissions",
|
|
25112
25174
|
inputs: [],
|
|
25175
|
+
name: "getLastBlockHash",
|
|
25113
25176
|
outputs: [
|
|
25114
25177
|
{
|
|
25115
|
-
|
|
25116
|
-
|
|
25117
|
-
|
|
25178
|
+
internalType: "bytes32",
|
|
25179
|
+
name: "blockHash",
|
|
25180
|
+
type: "bytes32",
|
|
25118
25181
|
},
|
|
25119
25182
|
],
|
|
25120
25183
|
stateMutability: "view",
|
|
25184
|
+
type: "function",
|
|
25121
25185
|
},
|
|
25122
25186
|
{
|
|
25123
|
-
type: "function",
|
|
25124
|
-
name: "rescue",
|
|
25125
25187
|
inputs: [
|
|
25126
25188
|
{
|
|
25127
|
-
|
|
25128
|
-
|
|
25129
|
-
|
|
25189
|
+
internalType: "bool",
|
|
25190
|
+
name: "requireSuccess",
|
|
25191
|
+
type: "bool",
|
|
25192
|
+
},
|
|
25193
|
+
{
|
|
25130
25194
|
components: [
|
|
25131
25195
|
{
|
|
25132
|
-
|
|
25196
|
+
internalType: "address",
|
|
25197
|
+
name: "target",
|
|
25133
25198
|
type: "address",
|
|
25134
|
-
internalType: "contract Flaunch",
|
|
25135
25199
|
},
|
|
25136
|
-
{
|
|
25200
|
+
{
|
|
25201
|
+
internalType: "bytes",
|
|
25202
|
+
name: "callData",
|
|
25203
|
+
type: "bytes",
|
|
25204
|
+
},
|
|
25137
25205
|
],
|
|
25206
|
+
internalType: "struct Multicall3.Call[]",
|
|
25207
|
+
name: "calls",
|
|
25208
|
+
type: "tuple[]",
|
|
25138
25209
|
},
|
|
25139
|
-
{ name: "_recipient", type: "address", internalType: "address" },
|
|
25140
25210
|
],
|
|
25141
|
-
|
|
25142
|
-
|
|
25143
|
-
|
|
25144
|
-
|
|
25145
|
-
|
|
25146
|
-
|
|
25147
|
-
|
|
25148
|
-
|
|
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
|
+
},
|
|
25149
25230
|
],
|
|
25150
|
-
|
|
25151
|
-
|
|
25231
|
+
stateMutability: "payable",
|
|
25232
|
+
type: "function",
|
|
25152
25233
|
},
|
|
25153
25234
|
{
|
|
25154
|
-
type: "function",
|
|
25155
|
-
name: "transferManagerOwnership",
|
|
25156
25235
|
inputs: [
|
|
25157
25236
|
{
|
|
25158
|
-
|
|
25159
|
-
|
|
25160
|
-
|
|
25237
|
+
internalType: "bool",
|
|
25238
|
+
name: "requireSuccess",
|
|
25239
|
+
type: "bool",
|
|
25161
25240
|
},
|
|
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
|
-
|
|
25201
|
-
|
|
25202
|
-
|
|
25203
|
-
|
|
25204
|
-
|
|
25205
|
-
|
|
25206
|
-
|
|
25207
|
-
|
|
25208
|
-
|
|
25209
|
-
|
|
25210
|
-
|
|
25211
|
-
|
|
25212
|
-
|
|
25213
|
-
|
|
25214
|
-
|
|
25215
|
-
|
|
25216
|
-
|
|
25217
|
-
|
|
25218
|
-
|
|
25219
|
-
|
|
25220
|
-
|
|
25221
|
-
|
|
25222
|
-
|
|
25223
|
-
});
|
|
25224
|
-
}
|
|
25225
|
-
/**
|
|
25226
|
-
* Sets the permissions contract address
|
|
25227
|
-
* @param permissions - The address of the new permissions contract
|
|
25228
|
-
* @returns Promise<void>
|
|
25229
|
-
*/
|
|
25230
|
-
setPermissions(permissions) {
|
|
25231
|
-
return this.contract.write("setPermissions", {
|
|
25232
|
-
_permissions: permissions,
|
|
25233
|
-
});
|
|
25234
|
-
}
|
|
25235
|
-
/**
|
|
25236
|
-
* Transfers the manager ownership to a new address
|
|
25237
|
-
* @param newManagerOwner - The address of the new manager owner
|
|
25238
|
-
* @returns Promise<void>
|
|
25239
|
-
*/
|
|
25240
|
-
transferManagerOwnership(newManagerOwner) {
|
|
25241
|
-
return this.contract.write("transferManagerOwnership", {
|
|
25242
|
-
_newManagerOwner: newManagerOwner,
|
|
25243
|
-
});
|
|
25244
|
-
}
|
|
25245
|
-
}
|
|
25246
|
-
|
|
25247
|
-
// our min/max tick range that is valid for the tick spacing (60)
|
|
25248
|
-
const TickFinder = {
|
|
25249
|
-
MIN_TICK: -887220,
|
|
25250
|
-
MAX_TICK: 887220,
|
|
25251
|
-
};
|
|
25252
|
-
const Q96 = 2n ** 96n;
|
|
25253
|
-
const Q192 = 2n ** 192n;
|
|
25254
|
-
const TICK_SPACING = 60;
|
|
25255
|
-
const getPoolId = (poolKey) => {
|
|
25256
|
-
// Pack the data in the same order as Solidity struct
|
|
25257
|
-
const packed = viem.concat([
|
|
25258
|
-
viem.pad(poolKey.currency0, { size: 32 }), // address padded to 32 bytes
|
|
25259
|
-
viem.pad(poolKey.currency1, { size: 32 }), // address padded to 32 bytes
|
|
25260
|
-
viem.pad(viem.toHex(poolKey.fee), { size: 32 }), // uint24 padded to 32 bytes
|
|
25261
|
-
viem.pad(viem.toHex(poolKey.tickSpacing), { size: 32 }), // int24 padded to 32 bytes
|
|
25262
|
-
viem.pad(poolKey.hooks, { size: 32 }), // address padded to 32 bytes
|
|
25263
|
-
]);
|
|
25264
|
-
return viem.keccak256(packed);
|
|
25265
|
-
};
|
|
25266
|
-
const orderPoolKey = (poolKey) => {
|
|
25267
|
-
const [currency0, currency1] = poolKey.currency0 < poolKey.currency1
|
|
25268
|
-
? [poolKey.currency0, poolKey.currency1]
|
|
25269
|
-
: [poolKey.currency1, poolKey.currency0];
|
|
25270
|
-
return {
|
|
25271
|
-
...poolKey,
|
|
25272
|
-
currency0,
|
|
25273
|
-
currency1,
|
|
25274
|
-
};
|
|
25275
|
-
};
|
|
25276
|
-
const getValidTick = ({ tick, tickSpacing, roundDown = true, }) => {
|
|
25277
|
-
// If the tick is already valid, exit early
|
|
25278
|
-
if (tick % tickSpacing === 0) {
|
|
25279
|
-
return tick;
|
|
25280
|
-
}
|
|
25281
|
-
// Division that rounds towards zero (like Solidity)
|
|
25282
|
-
let validTick = Math.trunc(tick / tickSpacing) * tickSpacing;
|
|
25283
|
-
// Handle negative ticks (Solidity behavior)
|
|
25284
|
-
if (tick < 0 && tick % tickSpacing !== 0) {
|
|
25285
|
-
validTick -= tickSpacing;
|
|
25286
|
-
}
|
|
25287
|
-
// If not rounding down, add TICK_SPACING to get the upper tick
|
|
25288
|
-
if (!roundDown) {
|
|
25289
|
-
validTick += tickSpacing;
|
|
25290
|
-
}
|
|
25291
|
-
return validTick;
|
|
25292
|
-
};
|
|
25293
|
-
// Rounds up or down to the nearest tick
|
|
25294
|
-
const getNearestUsableTick = ({ tick, tickSpacing, }) => {
|
|
25295
|
-
const rounded = Math.round(tick / tickSpacing) * tickSpacing;
|
|
25296
|
-
return Math.max(TickFinder.MIN_TICK, Math.min(TickFinder.MAX_TICK, rounded));
|
|
25297
|
-
};
|
|
25298
|
-
const getAmount0ForLiquidity = (sqrtRatioAX96, sqrtRatioBX96, liquidity) => {
|
|
25299
|
-
let [sqrtRatioA, sqrtRatioB] = [sqrtRatioAX96, sqrtRatioBX96];
|
|
25300
|
-
if (sqrtRatioA > sqrtRatioB) {
|
|
25301
|
-
[sqrtRatioA, sqrtRatioB] = [sqrtRatioB, sqrtRatioA];
|
|
25302
|
-
}
|
|
25303
|
-
const leftShiftedLiquidity = liquidity << 96n;
|
|
25304
|
-
const sqrtDiff = sqrtRatioB - sqrtRatioA;
|
|
25305
|
-
const multipliedRes = leftShiftedLiquidity * sqrtDiff;
|
|
25306
|
-
const numerator = multipliedRes / sqrtRatioB;
|
|
25307
|
-
const amount0 = numerator / sqrtRatioA;
|
|
25308
|
-
return amount0;
|
|
25309
|
-
};
|
|
25310
|
-
const getAmount1ForLiquidity = (sqrtRatioAX96, sqrtRatioBX96, liquidity) => {
|
|
25311
|
-
let [sqrtRatioA, sqrtRatioB] = [sqrtRatioAX96, sqrtRatioBX96];
|
|
25312
|
-
if (sqrtRatioA > sqrtRatioB) {
|
|
25313
|
-
[sqrtRatioA, sqrtRatioB] = [sqrtRatioB, sqrtRatioA];
|
|
25314
|
-
}
|
|
25315
|
-
const sqrtDiff = sqrtRatioB - sqrtRatioA;
|
|
25316
|
-
const multipliedRes = liquidity * sqrtDiff;
|
|
25317
|
-
const amount1 = multipliedRes / 2n ** 96n;
|
|
25318
|
-
return amount1;
|
|
25319
|
-
};
|
|
25320
|
-
const getSqrtPriceX96FromTick = (tick) => {
|
|
25321
|
-
const absTick = tick < 0 ? BigInt(-tick) : BigInt(tick);
|
|
25322
|
-
if (absTick > TickFinder.MAX_TICK) {
|
|
25323
|
-
throw new Error("Tick out of range");
|
|
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[]",
|
|
25257
|
+
},
|
|
25258
|
+
],
|
|
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
|
+
});
|
|
25324
25302
|
}
|
|
25325
|
-
|
|
25326
|
-
|
|
25327
|
-
|
|
25328
|
-
|
|
25329
|
-
|
|
25330
|
-
|
|
25331
|
-
|
|
25332
|
-
|
|
25333
|
-
ratio = (ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0n) >> 128n;
|
|
25334
|
-
if ((absTick & 16n) !== 0n)
|
|
25335
|
-
ratio = (ratio * 0xffcb9843d60f6159c9db58835c926644n) >> 128n;
|
|
25336
|
-
if ((absTick & 32n) !== 0n)
|
|
25337
|
-
ratio = (ratio * 0xff973b41fa98c081472e6896dfb254c0n) >> 128n;
|
|
25338
|
-
if ((absTick & 64n) !== 0n)
|
|
25339
|
-
ratio = (ratio * 0xff2ea16466c96a3843ec78b326b52861n) >> 128n;
|
|
25340
|
-
if ((absTick & 128n) !== 0n)
|
|
25341
|
-
ratio = (ratio * 0xfe5dee046a99a2a811c461f1969c3053n) >> 128n;
|
|
25342
|
-
if ((absTick & 256n) !== 0n)
|
|
25343
|
-
ratio = (ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4n) >> 128n;
|
|
25344
|
-
if ((absTick & 512n) !== 0n)
|
|
25345
|
-
ratio = (ratio * 0xf987a7253ac413176f2b074cf7815e54n) >> 128n;
|
|
25346
|
-
if ((absTick & 1024n) !== 0n)
|
|
25347
|
-
ratio = (ratio * 0xf3392b0822b70005940c7a398e4b70f3n) >> 128n;
|
|
25348
|
-
if ((absTick & 2048n) !== 0n)
|
|
25349
|
-
ratio = (ratio * 0xe7159475a2c29b7443b29c7fa6e889d9n) >> 128n;
|
|
25350
|
-
if ((absTick & 4096n) !== 0n)
|
|
25351
|
-
ratio = (ratio * 0xd097f3bdfd2022b8845ad8f792aa5825n) >> 128n;
|
|
25352
|
-
if ((absTick & 8192n) !== 0n)
|
|
25353
|
-
ratio = (ratio * 0xa9f746462d870fdf8a65dc1f90e061e5n) >> 128n;
|
|
25354
|
-
if ((absTick & 16384n) !== 0n)
|
|
25355
|
-
ratio = (ratio * 0x70d869a156d2a1b890bb3df62baf32f7n) >> 128n;
|
|
25356
|
-
if ((absTick & 32768n) !== 0n)
|
|
25357
|
-
ratio = (ratio * 0x31be135f97d08fd981231505542fcfa6n) >> 128n;
|
|
25358
|
-
if ((absTick & 65536n) !== 0n)
|
|
25359
|
-
ratio = (ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9n) >> 128n;
|
|
25360
|
-
if ((absTick & 131072n) !== 0n)
|
|
25361
|
-
ratio = (ratio * 0x5d6af8dedb81196699c329225ee604n) >> 128n;
|
|
25362
|
-
if ((absTick & 262144n) !== 0n)
|
|
25363
|
-
ratio = (ratio * 0x2216e584f5fa1ea926041bedfe98n) >> 128n;
|
|
25364
|
-
if ((absTick & 524288n) !== 0n)
|
|
25365
|
-
ratio = (ratio * 0x48a170391f7dc42444e8fa2n) >> 128n;
|
|
25366
|
-
if (tick > 0) {
|
|
25367
|
-
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
|
+
});
|
|
25368
25311
|
}
|
|
25369
|
-
|
|
25370
|
-
|
|
25371
|
-
|
|
25372
|
-
|
|
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
|
+
});
|
|
25373
25321
|
}
|
|
25374
|
-
|
|
25375
|
-
|
|
25376
|
-
|
|
25377
|
-
|
|
25378
|
-
|
|
25379
|
-
|
|
25380
|
-
|
|
25381
|
-
|
|
25382
|
-
|
|
25383
|
-
// Current price is below the position range
|
|
25384
|
-
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
|
+
});
|
|
25385
25331
|
}
|
|
25386
|
-
|
|
25387
|
-
|
|
25388
|
-
|
|
25389
|
-
|
|
25332
|
+
/**
|
|
25333
|
+
* Gets the protocol recipient address
|
|
25334
|
+
* @returns Promise<Address> - The protocol recipient address
|
|
25335
|
+
*/
|
|
25336
|
+
protocolRecipient() {
|
|
25337
|
+
return this.contract.read("protocolRecipient");
|
|
25390
25338
|
}
|
|
25391
|
-
|
|
25392
|
-
|
|
25393
|
-
|
|
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;
|
|
25394
25346
|
}
|
|
25395
|
-
|
|
25396
|
-
|
|
25397
|
-
|
|
25398
|
-
|
|
25399
|
-
|
|
25400
|
-
|
|
25401
|
-
|
|
25402
|
-
|
|
25403
|
-
|
|
25404
|
-
|
|
25405
|
-
|
|
25406
|
-
|
|
25407
|
-
// Input is token1 per token0 (e.g., memecoin per flETH)
|
|
25408
|
-
// Convert from human-readable to raw: divide by (10^decimals0 / 10^decimals1)
|
|
25409
|
-
priceRatio = inputPrice / Math.pow(10, decimals0 - decimals1);
|
|
25410
|
-
}
|
|
25411
|
-
else {
|
|
25412
|
-
// Input is token0 per token1 (e.g., flETH per memecoin)
|
|
25413
|
-
// Invert to get token1 per token0, then convert to raw
|
|
25414
|
-
priceRatio = 1 / inputPrice / Math.pow(10, decimals0 - decimals1);
|
|
25415
|
-
}
|
|
25416
|
-
// Calculate tick: tick = log(price) / log(1.0001)
|
|
25417
|
-
const tick = Math.log(priceRatio) / Math.log(1.0001);
|
|
25418
|
-
if (shouldGetNearestUsableTick) {
|
|
25419
|
-
return getValidTick({
|
|
25420
|
-
tick: Math.round(tick),
|
|
25421
|
-
tickSpacing: spacing,
|
|
25422
|
-
});
|
|
25423
|
-
}
|
|
25424
|
-
else {
|
|
25425
|
-
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();
|
|
25426
25359
|
}
|
|
25360
|
+
return tokens;
|
|
25427
25361
|
}
|
|
25428
|
-
|
|
25429
|
-
|
|
25430
|
-
|
|
25431
|
-
|
|
25432
|
-
|
|
25433
|
-
|
|
25434
|
-
|
|
25435
|
-
|
|
25436
|
-
|
|
25437
|
-
}
|
|
25438
|
-
|
|
25439
|
-
|
|
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();
|
|
25440
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));
|
|
25441
25383
|
}
|
|
25442
|
-
}
|
|
25443
|
-
|
|
25444
|
-
|
|
25445
|
-
|
|
25446
|
-
const getLiquidityFromAmounts = (params) => {
|
|
25447
|
-
const sqrtRatioCurrentX96 = getSqrtPriceX96FromTick(params.currentTick);
|
|
25448
|
-
let sqrtRatioAX96 = getSqrtPriceX96FromTick(params.tickLower);
|
|
25449
|
-
let sqrtRatioBX96 = getSqrtPriceX96FromTick(params.tickUpper);
|
|
25450
|
-
if (sqrtRatioAX96 > sqrtRatioBX96) {
|
|
25451
|
-
[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
|
|
25452
|
-
}
|
|
25453
|
-
if (sqrtRatioCurrentX96 <= sqrtRatioAX96) {
|
|
25454
|
-
return maxLiquidityForAmount0Precise(sqrtRatioAX96, sqrtRatioBX96, params.amount0);
|
|
25455
|
-
}
|
|
25456
|
-
else if (sqrtRatioCurrentX96 < sqrtRatioBX96) {
|
|
25457
|
-
const liquidity0 = maxLiquidityForAmount0Precise(sqrtRatioCurrentX96, sqrtRatioBX96, params.amount0);
|
|
25458
|
-
const liquidity1 = maxLiquidityForAmount1(sqrtRatioAX96, sqrtRatioCurrentX96, params.amount1);
|
|
25459
|
-
return liquidity0 < liquidity1 ? liquidity0 : liquidity1;
|
|
25384
|
+
}
|
|
25385
|
+
class ReadWriteRevenueManager extends ReadRevenueManager {
|
|
25386
|
+
constructor(address, drift$1 = drift.createDrift()) {
|
|
25387
|
+
super(address, drift$1);
|
|
25460
25388
|
}
|
|
25461
|
-
|
|
25462
|
-
|
|
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", {});
|
|
25463
25395
|
}
|
|
25464
|
-
|
|
25465
|
-
|
|
25466
|
-
|
|
25467
|
-
|
|
25468
|
-
|
|
25469
|
-
|
|
25470
|
-
* @param amount0 The token0 amount
|
|
25471
|
-
* @returns liquidity for amount0, precise
|
|
25472
|
-
*/
|
|
25473
|
-
function maxLiquidityForAmount0Precise(sqrtRatioAX96, sqrtRatioBX96, amount0) {
|
|
25474
|
-
if (sqrtRatioAX96 > sqrtRatioBX96) {
|
|
25475
|
-
[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
|
|
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", {});
|
|
25476
25402
|
}
|
|
25477
|
-
|
|
25478
|
-
|
|
25479
|
-
|
|
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
|
+
});
|
|
25480
25412
|
}
|
|
25481
|
-
const Q96 = 2n ** 96n;
|
|
25482
|
-
const numerator = amount0 * sqrtRatioAX96 * sqrtRatioBX96;
|
|
25483
|
-
const denominator = Q96 * (sqrtRatioBX96 - sqrtRatioAX96);
|
|
25484
|
-
return numerator / denominator;
|
|
25485
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
|
+
|
|
25486
25515
|
/**
|
|
25487
|
-
*
|
|
25488
|
-
*
|
|
25489
|
-
* @param sqrtRatioBX96 The price at the upper tick boundary
|
|
25490
|
-
* @param amount1 The token1 amount
|
|
25491
|
-
* @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
|
|
25492
25518
|
*/
|
|
25493
|
-
|
|
25494
|
-
|
|
25495
|
-
|
|
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
|
+
});
|
|
25496
25534
|
}
|
|
25497
|
-
|
|
25498
|
-
|
|
25499
|
-
|
|
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");
|
|
25500
25548
|
}
|
|
25501
|
-
const Q96 = 2n ** 96n;
|
|
25502
|
-
return (amount1 * Q96) / (sqrtRatioBX96 - sqrtRatioAX96);
|
|
25503
25549
|
}
|
|
25504
25550
|
/**
|
|
25505
|
-
*
|
|
25506
|
-
*
|
|
25551
|
+
* Extended client for interacting with the TreasuryManager contract with write capabilities
|
|
25552
|
+
* Provides methods to deposit tokens, set permissions, and transfer ownership
|
|
25507
25553
|
*/
|
|
25508
|
-
|
|
25509
|
-
|
|
25510
|
-
|
|
25511
|
-
return { amount0: 0n, amount1: 0n };
|
|
25512
|
-
}
|
|
25513
|
-
const sqrtRatioCurrentX96 = getSqrtPriceX96FromTick(params.currentTick);
|
|
25514
|
-
let sqrtRatioAX96 = getSqrtPriceX96FromTick(params.tickLower);
|
|
25515
|
-
let sqrtRatioBX96 = getSqrtPriceX96FromTick(params.tickUpper);
|
|
25516
|
-
if (sqrtRatioAX96 > sqrtRatioBX96) {
|
|
25517
|
-
[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
|
|
25554
|
+
class ReadWriteTreasuryManager extends ReadTreasuryManager {
|
|
25555
|
+
constructor(address, drift$1 = drift.createDrift()) {
|
|
25556
|
+
super(address, drift$1);
|
|
25518
25557
|
}
|
|
25519
|
-
|
|
25520
|
-
|
|
25521
|
-
|
|
25522
|
-
|
|
25523
|
-
|
|
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
|
+
});
|
|
25524
25571
|
}
|
|
25525
|
-
|
|
25526
|
-
|
|
25527
|
-
|
|
25528
|
-
|
|
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
|
+
});
|
|
25529
25581
|
}
|
|
25530
|
-
|
|
25531
|
-
|
|
25532
|
-
|
|
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
|
+
});
|
|
25533
25591
|
}
|
|
25534
|
-
|
|
25535
|
-
};
|
|
25592
|
+
}
|
|
25536
25593
|
|
|
25537
25594
|
const chainIdToChain = {
|
|
25538
25595
|
[base.id]: base,
|
|
@@ -27380,6 +27437,25 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
|
|
|
27380
27437
|
const hash = await this.readWriteFlaunchZap.deployStakingManager(params);
|
|
27381
27438
|
return await this.readWriteTreasuryManagerFactory.getManagerDeployedAddressFromTx(hash);
|
|
27382
27439
|
}
|
|
27440
|
+
/**
|
|
27441
|
+
* Deploys a new BuyBack manager
|
|
27442
|
+
* @param params - Parameters for deploying the BuyBack manager
|
|
27443
|
+
* @param params.managerOwner - The address of the manager owner
|
|
27444
|
+
* @param params.creatorSharePercent - The % share that a creator will earn from their token (0-100)
|
|
27445
|
+
* @param params.ownerSharePercent - The % share that the manager owner will earn from their token (0-100)
|
|
27446
|
+
* @param params.buyBackPoolKey - The Uniswap V4 pool key configuration for the buyback pool
|
|
27447
|
+
* @param params.buyBackPoolKey.currency0 - The lower currency of the pool (sorted numerically)
|
|
27448
|
+
* @param params.buyBackPoolKey.currency1 - The higher currency of the pool (sorted numerically)
|
|
27449
|
+
* @param params.buyBackPoolKey.fee - The pool LP fee, capped at 1_000_000
|
|
27450
|
+
* @param params.buyBackPoolKey.tickSpacing - Tick spacing for the pool
|
|
27451
|
+
* @param params.buyBackPoolKey.hooks - The hooks address of the pool
|
|
27452
|
+
* @param params.permissions - The permissions for the BuyBack manager
|
|
27453
|
+
* @returns Address of the deployed BuyBack manager
|
|
27454
|
+
*/
|
|
27455
|
+
async deployBuyBackManager(params) {
|
|
27456
|
+
const hash = await this.readWriteFlaunchZap.deployBuyBackManager(params);
|
|
27457
|
+
return await this.readWriteTreasuryManagerFactory.getManagerDeployedAddressFromTx(hash);
|
|
27458
|
+
}
|
|
27383
27459
|
/**
|
|
27384
27460
|
* Creates a new Flaunch on the specified version
|
|
27385
27461
|
* @param params - Parameters for creating the Flaunch
|
|
@@ -32023,6 +32099,7 @@ exports.BidWallAddress = BidWallAddress;
|
|
|
32023
32099
|
exports.BidWallV1_1Abi = BidWallV1_1Abi;
|
|
32024
32100
|
exports.BidWallV1_1Address = BidWallV1_1Address;
|
|
32025
32101
|
exports.BidwallAbi = BidwallAbi;
|
|
32102
|
+
exports.BuyBackManagerAddress = BuyBackManagerAddress;
|
|
32026
32103
|
exports.ClankerWorldVerifierAddress = ClankerWorldVerifierAddress;
|
|
32027
32104
|
exports.ClosedPermissionsAddress = ClosedPermissionsAddress;
|
|
32028
32105
|
exports.DopplerVerifierAddress = DopplerVerifierAddress;
|
|
@@ -32069,7 +32146,6 @@ exports.ReferralEscrowAbi = ReferralEscrowAbi;
|
|
|
32069
32146
|
exports.ReferralEscrowAddress = ReferralEscrowAddress;
|
|
32070
32147
|
exports.RevenueManagerAbi = RevenueManagerAbi;
|
|
32071
32148
|
exports.RevenueManagerAddress = RevenueManagerAddress;
|
|
32072
|
-
exports.SolanaVerifierAddress = SolanaVerifierAddress;
|
|
32073
32149
|
exports.StakingManagerAddress = StakingManagerAddress;
|
|
32074
32150
|
exports.StateViewAbi = StateViewAbi;
|
|
32075
32151
|
exports.StateViewAddress = StateViewAddress;
|