@whetstone-research/doppler-sdk 1.0.22 → 1.0.23
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 +33 -6
- package/dist/evm/index.cjs +395 -140
- package/dist/evm/index.cjs.map +1 -1
- package/dist/evm/index.d.cts +18 -1
- package/dist/evm/index.d.ts +18 -1
- package/dist/evm/index.js +396 -142
- package/dist/evm/index.js.map +1 -1
- package/package.json +1 -1
package/dist/evm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '../chunk-PZ5AY32C.js';
|
|
2
|
-
import { parseEther, formatEther, getAddress, encodeAbiParameters, keccak256, decodeAbiParameters, encodePacked, decodeEventLog, toHex, zeroAddress, zeroHash, encodeFunctionData,
|
|
2
|
+
import { parseEther, formatEther, getAddress, encodeAbiParameters, keccak256, decodeAbiParameters, encodePacked, decodeEventLog, toHex, zeroAddress, zeroHash, encodeFunctionData, BaseError, ContractFunctionRevertedError, ContractFunctionZeroDataError, multicall3Abi, decodeFunctionResult, decodeErrorResult } from 'viem';
|
|
3
3
|
|
|
4
4
|
// src/evm/deployments.generated.ts
|
|
5
5
|
var GENERATED_DOPPLER_DEPLOYMENTS = {
|
|
@@ -12375,120 +12375,16 @@ var DynamicAuction = class {
|
|
|
12375
12375
|
return value;
|
|
12376
12376
|
}
|
|
12377
12377
|
};
|
|
12378
|
-
|
|
12379
|
-
|
|
12380
|
-
|
|
12381
|
-
throw new Error(
|
|
12382
|
-
"Multicall3 address is not configured on this chain. Configure the viem chain multicall3 contract before previewing pending fees."
|
|
12383
|
-
);
|
|
12384
|
-
}
|
|
12385
|
-
return multicall3Address;
|
|
12386
|
-
}
|
|
12387
|
-
async function callAggregate3(client, calls) {
|
|
12388
|
-
const response = await client.call({
|
|
12389
|
-
to: getMulticall3Address(client),
|
|
12390
|
-
data: encodeFunctionData({
|
|
12391
|
-
abi: multicall3Abi,
|
|
12392
|
-
functionName: "aggregate3",
|
|
12393
|
-
args: [calls]
|
|
12394
|
-
})
|
|
12395
|
-
});
|
|
12396
|
-
if (!response.data) {
|
|
12397
|
-
throw new Error("Multicall3 aggregate3 returned no data");
|
|
12398
|
-
}
|
|
12399
|
-
return decodeFunctionResult({
|
|
12400
|
-
abi: multicall3Abi,
|
|
12401
|
-
functionName: "aggregate3",
|
|
12402
|
-
data: response.data
|
|
12403
|
-
});
|
|
12404
|
-
}
|
|
12405
|
-
var PENDING_FEE_CALL_ORDER = [
|
|
12406
|
-
"collectFees",
|
|
12407
|
-
"getShares",
|
|
12408
|
-
"getCumulatedFees0",
|
|
12409
|
-
"getCumulatedFees1",
|
|
12410
|
-
"getLastCumulatedFees0",
|
|
12411
|
-
"getLastCumulatedFees1"
|
|
12378
|
+
var ABSENT_POOL_ERROR_ABI = [
|
|
12379
|
+
{ type: "error", name: "PoolNotFound", inputs: [] },
|
|
12380
|
+
{ type: "error", name: "PoolNotInitialized", inputs: [] }
|
|
12412
12381
|
];
|
|
12413
|
-
function createPendingFeePreviewCalls(target, poolId, beneficiary) {
|
|
12414
|
-
return PENDING_FEE_CALL_ORDER.map((functionName) => ({
|
|
12415
|
-
target,
|
|
12416
|
-
allowFailure: true,
|
|
12417
|
-
callData: encodeFunctionData({
|
|
12418
|
-
abi: feeClaimsInitializerAbi,
|
|
12419
|
-
functionName,
|
|
12420
|
-
args: functionName === "collectFees" || functionName === "getCumulatedFees0" || functionName === "getCumulatedFees1" ? [poolId] : [poolId, beneficiary]
|
|
12421
|
-
})
|
|
12422
|
-
}));
|
|
12423
|
-
}
|
|
12424
|
-
function calculatePendingFees(callResults) {
|
|
12425
|
-
const preview = decodePendingFeePreview(callResults);
|
|
12426
|
-
if (preview.cumulatedFees0 < preview.lastCumulatedFees0) {
|
|
12427
|
-
throw new Error("Accumulated fees are below beneficiary checkpoint");
|
|
12428
|
-
}
|
|
12429
|
-
if (preview.cumulatedFees1 < preview.lastCumulatedFees1) {
|
|
12430
|
-
throw new Error("Accumulated fees are below beneficiary checkpoint");
|
|
12431
|
-
}
|
|
12432
|
-
return {
|
|
12433
|
-
fees0: (preview.cumulatedFees0 - preview.lastCumulatedFees0) * preview.shares / WAD,
|
|
12434
|
-
fees1: (preview.cumulatedFees1 - preview.lastCumulatedFees1) * preview.shares / WAD
|
|
12435
|
-
};
|
|
12436
|
-
}
|
|
12437
|
-
function decodePendingFeePreview(callResults) {
|
|
12438
|
-
if (callResults.length !== PENDING_FEE_CALL_ORDER.length) {
|
|
12439
|
-
throw new Error("Multicall3 aggregate3 returned an incomplete pool result");
|
|
12440
|
-
}
|
|
12441
|
-
for (const [index, result] of callResults.entries()) {
|
|
12442
|
-
const functionName = PENDING_FEE_CALL_ORDER[index];
|
|
12443
|
-
if (!result.success) {
|
|
12444
|
-
throw new Error(`${functionName} call failed`);
|
|
12445
|
-
}
|
|
12446
|
-
if (!result.returnData || result.returnData === "0x") {
|
|
12447
|
-
throw new Error(`${functionName} returned no data`);
|
|
12448
|
-
}
|
|
12449
|
-
}
|
|
12450
|
-
decodeFunctionResult({
|
|
12451
|
-
abi: feeClaimsInitializerAbi,
|
|
12452
|
-
functionName: "collectFees",
|
|
12453
|
-
data: callResults[0].returnData
|
|
12454
|
-
});
|
|
12455
|
-
return {
|
|
12456
|
-
shares: decodeUint256("getShares", callResults[1].returnData),
|
|
12457
|
-
cumulatedFees0: decodeUint256(
|
|
12458
|
-
"getCumulatedFees0",
|
|
12459
|
-
callResults[2].returnData
|
|
12460
|
-
),
|
|
12461
|
-
cumulatedFees1: decodeUint256(
|
|
12462
|
-
"getCumulatedFees1",
|
|
12463
|
-
callResults[3].returnData
|
|
12464
|
-
),
|
|
12465
|
-
lastCumulatedFees0: decodeUint256(
|
|
12466
|
-
"getLastCumulatedFees0",
|
|
12467
|
-
callResults[4].returnData
|
|
12468
|
-
),
|
|
12469
|
-
lastCumulatedFees1: decodeUint256(
|
|
12470
|
-
"getLastCumulatedFees1",
|
|
12471
|
-
callResults[5].returnData
|
|
12472
|
-
)
|
|
12473
|
-
};
|
|
12474
|
-
}
|
|
12475
|
-
function decodeUint256(functionName, data) {
|
|
12476
|
-
const value = decodeFunctionResult({
|
|
12477
|
-
abi: feeClaimsInitializerAbi,
|
|
12478
|
-
functionName,
|
|
12479
|
-
data
|
|
12480
|
-
});
|
|
12481
|
-
if (typeof value !== "bigint") {
|
|
12482
|
-
throw new Error(`${functionName} returned invalid data`);
|
|
12483
|
-
}
|
|
12484
|
-
return value;
|
|
12485
|
-
}
|
|
12486
12382
|
async function findMulticurveInitializerForPool({
|
|
12487
12383
|
client,
|
|
12488
12384
|
tokenAddress,
|
|
12489
12385
|
addresses
|
|
12490
12386
|
}) {
|
|
12491
|
-
const initializersToTry =
|
|
12387
|
+
const initializersToTry = getMulticurveInitializerCandidates(addresses);
|
|
12492
12388
|
if (initializersToTry.length === 0) {
|
|
12493
12389
|
throw new Error(
|
|
12494
12390
|
"No V4 multicurve initializer addresses configured for this chain"
|
|
@@ -12503,7 +12399,7 @@ async function findMulticurveInitializerForPool({
|
|
|
12503
12399
|
try {
|
|
12504
12400
|
stateData = await client.readContract({
|
|
12505
12401
|
address: initializerAddress,
|
|
12506
|
-
abi: kind
|
|
12402
|
+
abi: getMulticurveInitializerAbi(kind),
|
|
12507
12403
|
functionName: "getState",
|
|
12508
12404
|
args: [tokenAddress]
|
|
12509
12405
|
});
|
|
@@ -12517,21 +12413,14 @@ async function findMulticurveInitializerForPool({
|
|
|
12517
12413
|
);
|
|
12518
12414
|
continue;
|
|
12519
12415
|
}
|
|
12520
|
-
const
|
|
12521
|
-
|
|
12522
|
-
|
|
12523
|
-
|
|
12524
|
-
|
|
12525
|
-
|
|
12526
|
-
|
|
12527
|
-
|
|
12528
|
-
fee: poolKey.fee,
|
|
12529
|
-
tickSpacing: poolKey.tickSpacing,
|
|
12530
|
-
status,
|
|
12531
|
-
poolKey,
|
|
12532
|
-
farTick: Number(farTick)
|
|
12533
|
-
}
|
|
12534
|
-
};
|
|
12416
|
+
const discoveryResult = parseMulticurveInitializerDiscoveryResult({
|
|
12417
|
+
tokenAddress,
|
|
12418
|
+
initializerAddress,
|
|
12419
|
+
kind,
|
|
12420
|
+
stateData
|
|
12421
|
+
});
|
|
12422
|
+
if (isInitializedMulticurvePoolKey(discoveryResult.state.poolKey)) {
|
|
12423
|
+
return discoveryResult;
|
|
12535
12424
|
}
|
|
12536
12425
|
}
|
|
12537
12426
|
const notFoundError = new Error(
|
|
@@ -12555,7 +12444,7 @@ function parseMulticurvePoolKey(rawPoolKey) {
|
|
|
12555
12444
|
hooks: poolKeyStruct.hooks ?? poolKeyStruct[4]
|
|
12556
12445
|
};
|
|
12557
12446
|
}
|
|
12558
|
-
function
|
|
12447
|
+
function getMulticurveInitializerCandidates(addresses) {
|
|
12559
12448
|
return [
|
|
12560
12449
|
{
|
|
12561
12450
|
address: addresses.v4MulticurveInitializer,
|
|
@@ -12577,6 +12466,50 @@ function getInitializerCandidates(addresses) {
|
|
|
12577
12466
|
(entry) => Boolean(entry.address && entry.address !== zeroAddress)
|
|
12578
12467
|
);
|
|
12579
12468
|
}
|
|
12469
|
+
function getMulticurveInitializerAbi(kind) {
|
|
12470
|
+
return kind === "dopplerHook" ? dopplerHookInitializerAbi : v4MulticurveInitializerAbi;
|
|
12471
|
+
}
|
|
12472
|
+
function parseMulticurveInitializerDiscoveryResult({
|
|
12473
|
+
tokenAddress,
|
|
12474
|
+
initializerAddress,
|
|
12475
|
+
kind,
|
|
12476
|
+
stateData
|
|
12477
|
+
}) {
|
|
12478
|
+
const parsedState = kind === "dopplerHook" ? parseDopplerHookInitializerState(stateData) : parseStandardInitializerState(stateData);
|
|
12479
|
+
const { numeraire, status, poolKey, farTick } = parsedState;
|
|
12480
|
+
return {
|
|
12481
|
+
initializerAddress,
|
|
12482
|
+
state: {
|
|
12483
|
+
asset: tokenAddress,
|
|
12484
|
+
numeraire,
|
|
12485
|
+
fee: poolKey.fee,
|
|
12486
|
+
tickSpacing: poolKey.tickSpacing,
|
|
12487
|
+
status,
|
|
12488
|
+
poolKey,
|
|
12489
|
+
farTick: Number(farTick)
|
|
12490
|
+
}
|
|
12491
|
+
};
|
|
12492
|
+
}
|
|
12493
|
+
function isInitializedMulticurvePoolKey(poolKey) {
|
|
12494
|
+
return poolKey.hooks !== zeroAddress && poolKey.tickSpacing !== 0;
|
|
12495
|
+
}
|
|
12496
|
+
function isAbsentPoolRevertData(data) {
|
|
12497
|
+
if (data === "0x") {
|
|
12498
|
+
return false;
|
|
12499
|
+
}
|
|
12500
|
+
try {
|
|
12501
|
+
const decodedError = decodeErrorResult({
|
|
12502
|
+
abi: ABSENT_POOL_ERROR_ABI,
|
|
12503
|
+
data
|
|
12504
|
+
});
|
|
12505
|
+
return decodedError.errorName === "PoolNotFound" || decodedError.errorName === "PoolNotInitialized";
|
|
12506
|
+
} catch (error) {
|
|
12507
|
+
if (error instanceof Error) {
|
|
12508
|
+
return false;
|
|
12509
|
+
}
|
|
12510
|
+
throw error;
|
|
12511
|
+
}
|
|
12512
|
+
}
|
|
12580
12513
|
function parseStandardInitializerState(stateData) {
|
|
12581
12514
|
const state = stateData;
|
|
12582
12515
|
return {
|
|
@@ -12702,6 +12635,288 @@ function readStructField(value, fieldName, tupleIndex) {
|
|
|
12702
12635
|
}
|
|
12703
12636
|
return 0;
|
|
12704
12637
|
}
|
|
12638
|
+
function getMulticall3Address(client) {
|
|
12639
|
+
const multicall3Address = client.chain?.contracts?.multicall3?.address;
|
|
12640
|
+
if (!multicall3Address || multicall3Address === zeroAddress) {
|
|
12641
|
+
throw new Error(
|
|
12642
|
+
"Multicall3 address is not configured on this chain. Configure the viem chain multicall3 contract before previewing pending fees."
|
|
12643
|
+
);
|
|
12644
|
+
}
|
|
12645
|
+
return multicall3Address;
|
|
12646
|
+
}
|
|
12647
|
+
async function callAggregate3(client, calls) {
|
|
12648
|
+
const response = await client.call({
|
|
12649
|
+
to: getMulticall3Address(client),
|
|
12650
|
+
data: encodeFunctionData({
|
|
12651
|
+
abi: multicall3Abi,
|
|
12652
|
+
functionName: "aggregate3",
|
|
12653
|
+
args: [calls]
|
|
12654
|
+
})
|
|
12655
|
+
});
|
|
12656
|
+
if (!response.data) {
|
|
12657
|
+
throw new Error("Multicall3 aggregate3 returned no data");
|
|
12658
|
+
}
|
|
12659
|
+
return decodeFunctionResult({
|
|
12660
|
+
abi: multicall3Abi,
|
|
12661
|
+
functionName: "aggregate3",
|
|
12662
|
+
data: response.data
|
|
12663
|
+
});
|
|
12664
|
+
}
|
|
12665
|
+
var PENDING_FEE_CALL_ORDER = [
|
|
12666
|
+
"collectFees",
|
|
12667
|
+
"getShares",
|
|
12668
|
+
"getCumulatedFees0",
|
|
12669
|
+
"getCumulatedFees1",
|
|
12670
|
+
"getLastCumulatedFees0",
|
|
12671
|
+
"getLastCumulatedFees1"
|
|
12672
|
+
];
|
|
12673
|
+
var PENDING_FEE_PREVIEW_CALL_COUNT = PENDING_FEE_CALL_ORDER.length;
|
|
12674
|
+
function createPendingFeePreviewCalls(target, poolId, beneficiary) {
|
|
12675
|
+
return PENDING_FEE_CALL_ORDER.map((functionName) => ({
|
|
12676
|
+
target,
|
|
12677
|
+
allowFailure: true,
|
|
12678
|
+
callData: encodeFunctionData({
|
|
12679
|
+
abi: feeClaimsInitializerAbi,
|
|
12680
|
+
functionName,
|
|
12681
|
+
args: functionName === "collectFees" || functionName === "getCumulatedFees0" || functionName === "getCumulatedFees1" ? [poolId] : [poolId, beneficiary]
|
|
12682
|
+
})
|
|
12683
|
+
}));
|
|
12684
|
+
}
|
|
12685
|
+
function calculatePendingFees(callResults) {
|
|
12686
|
+
const preview = decodePendingFeePreview(callResults);
|
|
12687
|
+
if (preview.cumulatedFees0 < preview.lastCumulatedFees0) {
|
|
12688
|
+
throw new Error("Accumulated fees are below beneficiary checkpoint");
|
|
12689
|
+
}
|
|
12690
|
+
if (preview.cumulatedFees1 < preview.lastCumulatedFees1) {
|
|
12691
|
+
throw new Error("Accumulated fees are below beneficiary checkpoint");
|
|
12692
|
+
}
|
|
12693
|
+
return {
|
|
12694
|
+
fees0: (preview.cumulatedFees0 - preview.lastCumulatedFees0) * preview.shares / WAD,
|
|
12695
|
+
fees1: (preview.cumulatedFees1 - preview.lastCumulatedFees1) * preview.shares / WAD
|
|
12696
|
+
};
|
|
12697
|
+
}
|
|
12698
|
+
function decodePendingFeePreview(callResults) {
|
|
12699
|
+
if (callResults.length !== PENDING_FEE_CALL_ORDER.length) {
|
|
12700
|
+
throw new Error("Multicall3 aggregate3 returned an incomplete pool result");
|
|
12701
|
+
}
|
|
12702
|
+
for (const [index, result] of callResults.entries()) {
|
|
12703
|
+
const functionName = PENDING_FEE_CALL_ORDER[index];
|
|
12704
|
+
if (!result.success) {
|
|
12705
|
+
throw new Error(`${functionName} call failed`);
|
|
12706
|
+
}
|
|
12707
|
+
if (!result.returnData || result.returnData === "0x") {
|
|
12708
|
+
throw new Error(`${functionName} returned no data`);
|
|
12709
|
+
}
|
|
12710
|
+
}
|
|
12711
|
+
decodeFunctionResult({
|
|
12712
|
+
abi: feeClaimsInitializerAbi,
|
|
12713
|
+
functionName: "collectFees",
|
|
12714
|
+
data: callResults[0].returnData
|
|
12715
|
+
});
|
|
12716
|
+
return {
|
|
12717
|
+
shares: decodeUint256("getShares", callResults[1].returnData),
|
|
12718
|
+
cumulatedFees0: decodeUint256(
|
|
12719
|
+
"getCumulatedFees0",
|
|
12720
|
+
callResults[2].returnData
|
|
12721
|
+
),
|
|
12722
|
+
cumulatedFees1: decodeUint256(
|
|
12723
|
+
"getCumulatedFees1",
|
|
12724
|
+
callResults[3].returnData
|
|
12725
|
+
),
|
|
12726
|
+
lastCumulatedFees0: decodeUint256(
|
|
12727
|
+
"getLastCumulatedFees0",
|
|
12728
|
+
callResults[4].returnData
|
|
12729
|
+
),
|
|
12730
|
+
lastCumulatedFees1: decodeUint256(
|
|
12731
|
+
"getLastCumulatedFees1",
|
|
12732
|
+
callResults[5].returnData
|
|
12733
|
+
)
|
|
12734
|
+
};
|
|
12735
|
+
}
|
|
12736
|
+
function decodeUint256(functionName, data) {
|
|
12737
|
+
const value = decodeFunctionResult({
|
|
12738
|
+
abi: feeClaimsInitializerAbi,
|
|
12739
|
+
functionName,
|
|
12740
|
+
data
|
|
12741
|
+
});
|
|
12742
|
+
if (typeof value !== "bigint") {
|
|
12743
|
+
throw new Error(`${functionName} returned invalid data`);
|
|
12744
|
+
}
|
|
12745
|
+
return value;
|
|
12746
|
+
}
|
|
12747
|
+
|
|
12748
|
+
// src/evm/entities/auction/multicurve/multicurvePendingFeeReader.ts
|
|
12749
|
+
async function getPendingFeesForMulticurvePool({
|
|
12750
|
+
client,
|
|
12751
|
+
beneficiary,
|
|
12752
|
+
poolContext
|
|
12753
|
+
}) {
|
|
12754
|
+
const pendingFees = await getPendingFeesForDiscoveredMulticurvePools({
|
|
12755
|
+
client,
|
|
12756
|
+
beneficiary,
|
|
12757
|
+
poolContexts: [poolContext]
|
|
12758
|
+
});
|
|
12759
|
+
const poolPendingFees = pendingFees[0];
|
|
12760
|
+
if (!poolPendingFees) {
|
|
12761
|
+
throw new Error("Pending fee preview returned no pool result");
|
|
12762
|
+
}
|
|
12763
|
+
return {
|
|
12764
|
+
fees0: poolPendingFees.fees0,
|
|
12765
|
+
fees1: poolPendingFees.fees1
|
|
12766
|
+
};
|
|
12767
|
+
}
|
|
12768
|
+
async function getPendingFeesForMulticurveTokens({
|
|
12769
|
+
client,
|
|
12770
|
+
beneficiary,
|
|
12771
|
+
tokenAddresses
|
|
12772
|
+
}) {
|
|
12773
|
+
if (tokenAddresses.length === 0) {
|
|
12774
|
+
return [];
|
|
12775
|
+
}
|
|
12776
|
+
const feeClient = client;
|
|
12777
|
+
const poolContexts = await discoverMulticurveFeePoolContexts(
|
|
12778
|
+
feeClient,
|
|
12779
|
+
tokenAddresses
|
|
12780
|
+
);
|
|
12781
|
+
return getPendingFeesForDiscoveredMulticurvePools({
|
|
12782
|
+
client: feeClient,
|
|
12783
|
+
beneficiary,
|
|
12784
|
+
poolContexts
|
|
12785
|
+
});
|
|
12786
|
+
}
|
|
12787
|
+
async function discoverMulticurveFeePoolContexts(client, tokenAddresses) {
|
|
12788
|
+
const chainId = await client.getChainId();
|
|
12789
|
+
const addresses = getAddresses(chainId);
|
|
12790
|
+
const initializers = getMulticurveInitializerCandidates(addresses);
|
|
12791
|
+
if (initializers.length === 0) {
|
|
12792
|
+
throw new Error(
|
|
12793
|
+
"No V4 multicurve initializer addresses configured for this chain"
|
|
12794
|
+
);
|
|
12795
|
+
}
|
|
12796
|
+
const discoveryContexts = createDiscoveryCallContexts(
|
|
12797
|
+
tokenAddresses,
|
|
12798
|
+
initializers
|
|
12799
|
+
);
|
|
12800
|
+
const discoveryResults = await callAggregate3(
|
|
12801
|
+
client,
|
|
12802
|
+
createDiscoveryCalls(discoveryContexts)
|
|
12803
|
+
);
|
|
12804
|
+
if (discoveryResults.length !== discoveryContexts.length) {
|
|
12805
|
+
throw new Error(
|
|
12806
|
+
"Multicall3 aggregate3 returned an incomplete initializer discovery result"
|
|
12807
|
+
);
|
|
12808
|
+
}
|
|
12809
|
+
return tokenAddresses.map(
|
|
12810
|
+
(tokenAddress, tokenIndex) => findInitializedPoolForToken({
|
|
12811
|
+
tokenAddress,
|
|
12812
|
+
initializers,
|
|
12813
|
+
discoveryResults: discoveryResults.slice(
|
|
12814
|
+
tokenIndex * initializers.length,
|
|
12815
|
+
(tokenIndex + 1) * initializers.length
|
|
12816
|
+
)
|
|
12817
|
+
})
|
|
12818
|
+
);
|
|
12819
|
+
}
|
|
12820
|
+
function createDiscoveryCallContexts(tokenAddresses, initializers) {
|
|
12821
|
+
return tokenAddresses.flatMap(
|
|
12822
|
+
(tokenAddress) => initializers.map((initializer) => ({
|
|
12823
|
+
tokenAddress,
|
|
12824
|
+
initializer
|
|
12825
|
+
}))
|
|
12826
|
+
);
|
|
12827
|
+
}
|
|
12828
|
+
function createDiscoveryCalls(contexts) {
|
|
12829
|
+
return contexts.map(({ tokenAddress, initializer }) => ({
|
|
12830
|
+
target: initializer.address,
|
|
12831
|
+
allowFailure: true,
|
|
12832
|
+
callData: encodeFunctionData({
|
|
12833
|
+
abi: getMulticurveInitializerAbi(initializer.kind),
|
|
12834
|
+
functionName: "getState",
|
|
12835
|
+
args: [tokenAddress]
|
|
12836
|
+
})
|
|
12837
|
+
}));
|
|
12838
|
+
}
|
|
12839
|
+
function findInitializedPoolForToken({
|
|
12840
|
+
tokenAddress,
|
|
12841
|
+
initializers,
|
|
12842
|
+
discoveryResults
|
|
12843
|
+
}) {
|
|
12844
|
+
for (const [index, result] of discoveryResults.entries()) {
|
|
12845
|
+
const initializer = initializers[index];
|
|
12846
|
+
if (!initializer) {
|
|
12847
|
+
throw new Error(
|
|
12848
|
+
"Multicall3 aggregate3 returned an incomplete initializer discovery result"
|
|
12849
|
+
);
|
|
12850
|
+
}
|
|
12851
|
+
if (!result.success) {
|
|
12852
|
+
if (isAbsentPoolRevertData(result.returnData)) {
|
|
12853
|
+
continue;
|
|
12854
|
+
}
|
|
12855
|
+
throw new Error(
|
|
12856
|
+
`${initializer.address} getState failed for token ${tokenAddress}`
|
|
12857
|
+
);
|
|
12858
|
+
}
|
|
12859
|
+
if (!result.returnData || result.returnData === "0x") {
|
|
12860
|
+
throw new Error(
|
|
12861
|
+
`${initializer.address} getState returned no data for token ${tokenAddress}`
|
|
12862
|
+
);
|
|
12863
|
+
}
|
|
12864
|
+
const discoveryResult = parseMulticurveInitializerDiscoveryResult({
|
|
12865
|
+
tokenAddress,
|
|
12866
|
+
initializerAddress: initializer.address,
|
|
12867
|
+
kind: initializer.kind,
|
|
12868
|
+
stateData: decodeFunctionResult({
|
|
12869
|
+
abi: getMulticurveInitializerAbi(initializer.kind),
|
|
12870
|
+
functionName: "getState",
|
|
12871
|
+
data: result.returnData
|
|
12872
|
+
})
|
|
12873
|
+
});
|
|
12874
|
+
if (isInitializedMulticurvePoolKey(discoveryResult.state.poolKey)) {
|
|
12875
|
+
assertPendingFeePreviewable(discoveryResult);
|
|
12876
|
+
return discoveryResult;
|
|
12877
|
+
}
|
|
12878
|
+
}
|
|
12879
|
+
throw new Error(
|
|
12880
|
+
`Pool not found for token ${tokenAddress}. Tried initializers: ${initializers.map((initializer) => initializer.address).join(", ")}`
|
|
12881
|
+
);
|
|
12882
|
+
}
|
|
12883
|
+
function assertPendingFeePreviewable(discoveryResult) {
|
|
12884
|
+
const { asset, status } = discoveryResult.state;
|
|
12885
|
+
if (status === 3 /* Exited */) {
|
|
12886
|
+
throw new Error(
|
|
12887
|
+
`Pending fee preview is only supported for initializer-side multicurve pools: ${asset}`
|
|
12888
|
+
);
|
|
12889
|
+
}
|
|
12890
|
+
if (status !== 2 /* Locked */) {
|
|
12891
|
+
throw new Error(`Multicurve pool is not locked or was migrated: ${asset}`);
|
|
12892
|
+
}
|
|
12893
|
+
}
|
|
12894
|
+
async function getPendingFeesForDiscoveredMulticurvePools({
|
|
12895
|
+
client,
|
|
12896
|
+
beneficiary,
|
|
12897
|
+
poolContexts
|
|
12898
|
+
}) {
|
|
12899
|
+
for (const poolContext of poolContexts) {
|
|
12900
|
+
assertPendingFeePreviewable(poolContext);
|
|
12901
|
+
}
|
|
12902
|
+
const previewCalls = poolContexts.flatMap(
|
|
12903
|
+
({ initializerAddress, state }) => createPendingFeePreviewCalls(
|
|
12904
|
+
initializerAddress,
|
|
12905
|
+
computePoolId(state.poolKey),
|
|
12906
|
+
beneficiary
|
|
12907
|
+
)
|
|
12908
|
+
);
|
|
12909
|
+
const previewResults = await callAggregate3(client, previewCalls);
|
|
12910
|
+
return poolContexts.map(({ state }, index) => ({
|
|
12911
|
+
tokenAddress: state.asset,
|
|
12912
|
+
...calculatePendingFees(
|
|
12913
|
+
previewResults.slice(
|
|
12914
|
+
index * PENDING_FEE_PREVIEW_CALL_COUNT,
|
|
12915
|
+
(index + 1) * PENDING_FEE_PREVIEW_CALL_COUNT
|
|
12916
|
+
)
|
|
12917
|
+
)
|
|
12918
|
+
}));
|
|
12919
|
+
}
|
|
12705
12920
|
|
|
12706
12921
|
// src/evm/entities/auction/MulticurvePool.ts
|
|
12707
12922
|
var MulticurvePool = class {
|
|
@@ -12780,21 +12995,11 @@ var MulticurvePool = class {
|
|
|
12780
12995
|
* Preview pending fees for a beneficiary on an initializer-side multicurve pool.
|
|
12781
12996
|
*/
|
|
12782
12997
|
async getPendingFees(beneficiary) {
|
|
12783
|
-
|
|
12784
|
-
|
|
12785
|
-
|
|
12786
|
-
|
|
12787
|
-
|
|
12788
|
-
}
|
|
12789
|
-
if (state.status !== 2 /* Locked */) {
|
|
12790
|
-
throw new Error("Multicurve pool is not locked or was migrated");
|
|
12791
|
-
}
|
|
12792
|
-
const poolId = computePoolId(state.poolKey);
|
|
12793
|
-
const callResults = await callAggregate3(
|
|
12794
|
-
this.rpc,
|
|
12795
|
-
createPendingFeePreviewCalls(initializerAddress, poolId, beneficiary)
|
|
12796
|
-
);
|
|
12797
|
-
return calculatePendingFees(callResults);
|
|
12998
|
+
return getPendingFeesForMulticurvePool({
|
|
12999
|
+
client: this.rpc,
|
|
13000
|
+
beneficiary,
|
|
13001
|
+
poolContext: await this.findInitializerForPool()
|
|
13002
|
+
});
|
|
12798
13003
|
}
|
|
12799
13004
|
/**
|
|
12800
13005
|
* Get the numeraire address for this pool
|
|
@@ -12814,6 +13019,55 @@ var MulticurvePool = class {
|
|
|
12814
13019
|
}
|
|
12815
13020
|
};
|
|
12816
13021
|
|
|
13022
|
+
// src/evm/entities/auction/MulticurveFees.ts
|
|
13023
|
+
var MulticurveFees = class {
|
|
13024
|
+
client;
|
|
13025
|
+
tokenAddresses;
|
|
13026
|
+
options;
|
|
13027
|
+
constructor(client, _walletClient, tokenAddresses, options = {}) {
|
|
13028
|
+
this.client = client;
|
|
13029
|
+
this.tokenAddresses = [...tokenAddresses];
|
|
13030
|
+
this.options = { ...options };
|
|
13031
|
+
}
|
|
13032
|
+
async getPendingFees(beneficiary, tokenAddressesOrOptions, options) {
|
|
13033
|
+
const hasTokenAddressOverride = isTokenAddressList(tokenAddressesOrOptions);
|
|
13034
|
+
const tokenAddresses = hasTokenAddressOverride ? tokenAddressesOrOptions : this.tokenAddresses;
|
|
13035
|
+
const callOptions = hasTokenAddressOverride ? options : tokenAddressesOrOptions;
|
|
13036
|
+
const tokenBatchSize = getTokenBatchSize(
|
|
13037
|
+
callOptions?.tokenBatchSize ?? this.options.tokenBatchSize
|
|
13038
|
+
);
|
|
13039
|
+
if (!tokenBatchSize || tokenAddresses.length <= tokenBatchSize) {
|
|
13040
|
+
return getPendingFeesForMulticurveTokens({
|
|
13041
|
+
client: this.client,
|
|
13042
|
+
beneficiary,
|
|
13043
|
+
tokenAddresses
|
|
13044
|
+
});
|
|
13045
|
+
}
|
|
13046
|
+
let pendingFees = [];
|
|
13047
|
+
for (let index = 0; index < tokenAddresses.length; index += tokenBatchSize) {
|
|
13048
|
+
const batchPendingFees = await getPendingFeesForMulticurveTokens({
|
|
13049
|
+
client: this.client,
|
|
13050
|
+
beneficiary,
|
|
13051
|
+
tokenAddresses: tokenAddresses.slice(index, index + tokenBatchSize)
|
|
13052
|
+
});
|
|
13053
|
+
pendingFees = [...pendingFees, ...batchPendingFees];
|
|
13054
|
+
}
|
|
13055
|
+
return pendingFees;
|
|
13056
|
+
}
|
|
13057
|
+
};
|
|
13058
|
+
function isTokenAddressList(value) {
|
|
13059
|
+
return Array.isArray(value);
|
|
13060
|
+
}
|
|
13061
|
+
function getTokenBatchSize(tokenBatchSize) {
|
|
13062
|
+
if (tokenBatchSize === void 0) {
|
|
13063
|
+
return void 0;
|
|
13064
|
+
}
|
|
13065
|
+
if (!Number.isInteger(tokenBatchSize) || tokenBatchSize < 1) {
|
|
13066
|
+
throw new Error("tokenBatchSize must be a positive integer");
|
|
13067
|
+
}
|
|
13068
|
+
return tokenBatchSize;
|
|
13069
|
+
}
|
|
13070
|
+
|
|
12817
13071
|
// src/evm/entities/auction/RehypeDopplerHook.ts
|
|
12818
13072
|
var RehypeDopplerHook = class {
|
|
12819
13073
|
client;
|
|
@@ -18985,6 +19239,6 @@ var DopplerSDK = class {
|
|
|
18985
19239
|
// src/evm/index.ts
|
|
18986
19240
|
var VERSION = "1.0.0";
|
|
18987
19241
|
|
|
18988
|
-
export { ADDRESSES, BASIS_POINTS, CHAIN_IDS, DAY_SECONDS, DEAD_ADDRESS, DECAY_MAX_START_FEE, DEFAULT_AIRLOCK_BENEFICIARY_SHARES, DEFAULT_AUCTION_DURATION, DEFAULT_EPOCH_LENGTH, DEFAULT_LOCK_DURATION, DEFAULT_MULTICURVE_LOWER_TICKS, DEFAULT_MULTICURVE_MAX_SUPPLY_SHARES, DEFAULT_MULTICURVE_NUM_POSITIONS, DEFAULT_MULTICURVE_UPPER_TICKS, DEFAULT_OPENING_AUCTION_DURATION, DEFAULT_OPENING_AUCTION_FEE, DEFAULT_OPENING_AUCTION_INCENTIVE_SHARE_BPS, DEFAULT_OPENING_AUCTION_MIN_ACCEPTABLE_TICK_TOKEN0, DEFAULT_OPENING_AUCTION_MIN_ACCEPTABLE_TICK_TOKEN1, DEFAULT_OPENING_AUCTION_MIN_LIQUIDITY, DEFAULT_OPENING_AUCTION_SHARE_TO_AUCTION_BPS, DEFAULT_OPENING_DOPPLER_DURATION, DEFAULT_OPENING_DOPPLER_EPOCH_LENGTH, DEFAULT_OPENING_DOPPLER_FEE, DEFAULT_OPENING_DOPPLER_NUM_PD_SLUGS, DEFAULT_OPENING_DOPPLER_TICK_SPACING, DEFAULT_PD_SLUGS, DEFAULT_V3_END_TICK, DEFAULT_V3_FEE, DEFAULT_V3_INITIAL_PROPOSAL_THRESHOLD, DEFAULT_V3_INITIAL_SUPPLY, DEFAULT_V3_INITIAL_VOTING_DELAY, DEFAULT_V3_INITIAL_VOTING_PERIOD, DEFAULT_V3_MAX_SHARE_TO_BE_SOLD, DEFAULT_V3_NUM_POSITIONS, DEFAULT_V3_NUM_TOKENS_TO_SELL, DEFAULT_V3_PRE_MINT, DEFAULT_V3_START_TICK, DEFAULT_V3_VESTING_DURATION, DEFAULT_V3_YEARLY_MINT_RATE, DEFAULT_V4_INITIAL_PROPOSAL_THRESHOLD, DEFAULT_V4_INITIAL_VOTING_DELAY, DEFAULT_V4_INITIAL_VOTING_PERIOD, DEFAULT_V4_YEARLY_MINT_RATE, derc2080_default as DERC2080Bytecode, derc20_default as DERC20Bytecode, DOPPLER_FLAGS, DOPPLER_MAX_TICK_SPACING, DYNAMIC_FEE_FLAG, Derc20, Derc20V2, doppler_default as DopplerBytecode, dopplerDN404_default as DopplerDN404Bytecode, DopplerERC20V1, DopplerFactory, DopplerSDK, DynamicAuction, DynamicAuctionBuilder, Eth, FEE_AMOUNT_MASK, FEE_TIERS, FLAG_MASK, INT24_MAX, INT24_MIN, LAUNCHPAD_ENABLED_CHAIN_IDS, LockablePoolStatus, MAX_SQRT_RATIO, MAX_TICK, MIN_SQRT_RATIO, MIN_TICK, MulticurveBuilder, MulticurvePool, NO_OP_ENABLED_CHAIN_IDS, OPENING_AUCTION_FLAGS, OPENING_AUCTION_PHASE_ACTIVE, OPENING_AUCTION_PHASE_CLOSED, OPENING_AUCTION_PHASE_NOT_STARTED, OPENING_AUCTION_PHASE_SETTLED, OPENING_AUCTION_STATUS_ACTIVE, OPENING_AUCTION_STATUS_DOPPLER_ACTIVE, OPENING_AUCTION_STATUS_EXITED, OPENING_AUCTION_STATUS_UNINITIALIZED, OpeningAuction, OpeningAuctionBidManager, OpeningAuctionBuilder, openingAuction_default as OpeningAuctionBytecode, OpeningAuctionLifecycle, OpeningAuctionPhase, OpeningAuctionPositionManager, OpeningAuctionStatus, Q96, Quoter, RehypeDopplerHook, RehypeDopplerHookMigrator, RehypeFeeRoutingMode, SECONDS_PER_DAY, SECONDS_PER_YEAR, SUPPORTED_CHAIN_IDS, stateView_default as StateViewBytecode, StaticAuction, StaticAuctionBuilder, TICK_SPACINGS, TopUpDistributor, V3_FEE_TIERS, V4_MAX_FEE, VALID_FEE_TIERS, VERSION, WAD, ZERO_ADDRESS, airlockAbi, applyTickOffsets, bundlerAbi, calculateFDV, calculateGamma, calculateMarketCap, calculateTickRange, calculateTokensToSell, computeOptimalGamma, computePoolId, createAirlockBeneficiary, decayMulticurveInitializerHookAbi, decodeBalanceDelta, derc20Abi, derc20V2Abi, dopplerERC20V1Abi, dopplerHookAbi, dopplerHookInitializerAbi, dopplerLensAbi, encodeRehypeDopplerHookMigratorCalldata, estimatePriceAtEpoch, estimateSlippage, feeClaimsInitializerAbi, formatTickAsPrice, getAddresses, getAirlockBeneficiary, getAirlockOwner, getAmount0ForLiquidity, getAmount1ForLiquidity, getLiquidityForAmount0, getLiquidityForAmount1, getMaxTickRounded, getNearestUsableTick, getSqrtRatioAtTick, getTickAtSqrtRatio, isLaunchpadEnabledChain, isNoOpEnabledChain, isSupportedChainId, isToken0Expected, isToken1, lockableUniswapV3InitializerAbi, marketCapToTickForMulticurve, marketCapToTicksForDynamicAuction, marketCapToTicksForMulticurve, marketCapToTicksForStaticAuction, marketCapToTokenPrice, mineTokenAddress, normalizePoolKey, openingAuctionAbi, openingAuctionInitializerAbi, openingAuctionPositionManagerAbi, poolManagerAbi, priceToSqrtPriceX96, priceToTick, quoterV2Abi, ratioToTick, rehypeDopplerHookAbi, rehypeDopplerHookMigratorAbi, resolveGasEstimate, sqrtPriceX96ToPrice, streamableFeesLockerAbi, streamableFeesLockerV2Abi, tickToMarketCap, tickToPrice, tokenPriceToRatio, topUpDistributorAbi, uniswapV2Router02Abi, uniswapV3InitializerAbi, uniswapV3PoolAbi, uniswapV4InitializerAbi, v2MigratorAbi, v3MigratorAbi, v4MigratorAbi, v4MulticurveInitializerAbi, v4MulticurveMigratorAbi, v4QuoterAbi, validateMarketCapParameters, weth9Abi };
|
|
19242
|
+
export { ADDRESSES, BASIS_POINTS, CHAIN_IDS, DAY_SECONDS, DEAD_ADDRESS, DECAY_MAX_START_FEE, DEFAULT_AIRLOCK_BENEFICIARY_SHARES, DEFAULT_AUCTION_DURATION, DEFAULT_EPOCH_LENGTH, DEFAULT_LOCK_DURATION, DEFAULT_MULTICURVE_LOWER_TICKS, DEFAULT_MULTICURVE_MAX_SUPPLY_SHARES, DEFAULT_MULTICURVE_NUM_POSITIONS, DEFAULT_MULTICURVE_UPPER_TICKS, DEFAULT_OPENING_AUCTION_DURATION, DEFAULT_OPENING_AUCTION_FEE, DEFAULT_OPENING_AUCTION_INCENTIVE_SHARE_BPS, DEFAULT_OPENING_AUCTION_MIN_ACCEPTABLE_TICK_TOKEN0, DEFAULT_OPENING_AUCTION_MIN_ACCEPTABLE_TICK_TOKEN1, DEFAULT_OPENING_AUCTION_MIN_LIQUIDITY, DEFAULT_OPENING_AUCTION_SHARE_TO_AUCTION_BPS, DEFAULT_OPENING_DOPPLER_DURATION, DEFAULT_OPENING_DOPPLER_EPOCH_LENGTH, DEFAULT_OPENING_DOPPLER_FEE, DEFAULT_OPENING_DOPPLER_NUM_PD_SLUGS, DEFAULT_OPENING_DOPPLER_TICK_SPACING, DEFAULT_PD_SLUGS, DEFAULT_V3_END_TICK, DEFAULT_V3_FEE, DEFAULT_V3_INITIAL_PROPOSAL_THRESHOLD, DEFAULT_V3_INITIAL_SUPPLY, DEFAULT_V3_INITIAL_VOTING_DELAY, DEFAULT_V3_INITIAL_VOTING_PERIOD, DEFAULT_V3_MAX_SHARE_TO_BE_SOLD, DEFAULT_V3_NUM_POSITIONS, DEFAULT_V3_NUM_TOKENS_TO_SELL, DEFAULT_V3_PRE_MINT, DEFAULT_V3_START_TICK, DEFAULT_V3_VESTING_DURATION, DEFAULT_V3_YEARLY_MINT_RATE, DEFAULT_V4_INITIAL_PROPOSAL_THRESHOLD, DEFAULT_V4_INITIAL_VOTING_DELAY, DEFAULT_V4_INITIAL_VOTING_PERIOD, DEFAULT_V4_YEARLY_MINT_RATE, derc2080_default as DERC2080Bytecode, derc20_default as DERC20Bytecode, DOPPLER_FLAGS, DOPPLER_MAX_TICK_SPACING, DYNAMIC_FEE_FLAG, Derc20, Derc20V2, doppler_default as DopplerBytecode, dopplerDN404_default as DopplerDN404Bytecode, DopplerERC20V1, DopplerFactory, DopplerSDK, DynamicAuction, DynamicAuctionBuilder, Eth, FEE_AMOUNT_MASK, FEE_TIERS, FLAG_MASK, INT24_MAX, INT24_MIN, LAUNCHPAD_ENABLED_CHAIN_IDS, LockablePoolStatus, MAX_SQRT_RATIO, MAX_TICK, MIN_SQRT_RATIO, MIN_TICK, MulticurveBuilder, MulticurveFees, MulticurvePool, NO_OP_ENABLED_CHAIN_IDS, OPENING_AUCTION_FLAGS, OPENING_AUCTION_PHASE_ACTIVE, OPENING_AUCTION_PHASE_CLOSED, OPENING_AUCTION_PHASE_NOT_STARTED, OPENING_AUCTION_PHASE_SETTLED, OPENING_AUCTION_STATUS_ACTIVE, OPENING_AUCTION_STATUS_DOPPLER_ACTIVE, OPENING_AUCTION_STATUS_EXITED, OPENING_AUCTION_STATUS_UNINITIALIZED, OpeningAuction, OpeningAuctionBidManager, OpeningAuctionBuilder, openingAuction_default as OpeningAuctionBytecode, OpeningAuctionLifecycle, OpeningAuctionPhase, OpeningAuctionPositionManager, OpeningAuctionStatus, Q96, Quoter, RehypeDopplerHook, RehypeDopplerHookMigrator, RehypeFeeRoutingMode, SECONDS_PER_DAY, SECONDS_PER_YEAR, SUPPORTED_CHAIN_IDS, stateView_default as StateViewBytecode, StaticAuction, StaticAuctionBuilder, TICK_SPACINGS, TopUpDistributor, V3_FEE_TIERS, V4_MAX_FEE, VALID_FEE_TIERS, VERSION, WAD, ZERO_ADDRESS, airlockAbi, applyTickOffsets, bundlerAbi, calculateFDV, calculateGamma, calculateMarketCap, calculateTickRange, calculateTokensToSell, computeOptimalGamma, computePoolId, createAirlockBeneficiary, decayMulticurveInitializerHookAbi, decodeBalanceDelta, derc20Abi, derc20V2Abi, dopplerERC20V1Abi, dopplerHookAbi, dopplerHookInitializerAbi, dopplerLensAbi, encodeRehypeDopplerHookMigratorCalldata, estimatePriceAtEpoch, estimateSlippage, feeClaimsInitializerAbi, formatTickAsPrice, getAddresses, getAirlockBeneficiary, getAirlockOwner, getAmount0ForLiquidity, getAmount1ForLiquidity, getLiquidityForAmount0, getLiquidityForAmount1, getMaxTickRounded, getNearestUsableTick, getSqrtRatioAtTick, getTickAtSqrtRatio, isLaunchpadEnabledChain, isNoOpEnabledChain, isSupportedChainId, isToken0Expected, isToken1, lockableUniswapV3InitializerAbi, marketCapToTickForMulticurve, marketCapToTicksForDynamicAuction, marketCapToTicksForMulticurve, marketCapToTicksForStaticAuction, marketCapToTokenPrice, mineTokenAddress, normalizePoolKey, openingAuctionAbi, openingAuctionInitializerAbi, openingAuctionPositionManagerAbi, poolManagerAbi, priceToSqrtPriceX96, priceToTick, quoterV2Abi, ratioToTick, rehypeDopplerHookAbi, rehypeDopplerHookMigratorAbi, resolveGasEstimate, sqrtPriceX96ToPrice, streamableFeesLockerAbi, streamableFeesLockerV2Abi, tickToMarketCap, tickToPrice, tokenPriceToRatio, topUpDistributorAbi, uniswapV2Router02Abi, uniswapV3InitializerAbi, uniswapV3PoolAbi, uniswapV4InitializerAbi, v2MigratorAbi, v3MigratorAbi, v4MigratorAbi, v4MulticurveInitializerAbi, v4MulticurveMigratorAbi, v4QuoterAbi, validateMarketCapParameters, weth9Abi };
|
|
18989
19243
|
//# sourceMappingURL=index.js.map
|
|
18990
19244
|
//# sourceMappingURL=index.js.map
|