@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.cjs
CHANGED
|
@@ -12377,120 +12377,16 @@ var DynamicAuction = class {
|
|
|
12377
12377
|
return value;
|
|
12378
12378
|
}
|
|
12379
12379
|
};
|
|
12380
|
-
|
|
12381
|
-
|
|
12382
|
-
|
|
12383
|
-
throw new Error(
|
|
12384
|
-
"Multicall3 address is not configured on this chain. Configure the viem chain multicall3 contract before previewing pending fees."
|
|
12385
|
-
);
|
|
12386
|
-
}
|
|
12387
|
-
return multicall3Address;
|
|
12388
|
-
}
|
|
12389
|
-
async function callAggregate3(client, calls) {
|
|
12390
|
-
const response = await client.call({
|
|
12391
|
-
to: getMulticall3Address(client),
|
|
12392
|
-
data: viem.encodeFunctionData({
|
|
12393
|
-
abi: viem.multicall3Abi,
|
|
12394
|
-
functionName: "aggregate3",
|
|
12395
|
-
args: [calls]
|
|
12396
|
-
})
|
|
12397
|
-
});
|
|
12398
|
-
if (!response.data) {
|
|
12399
|
-
throw new Error("Multicall3 aggregate3 returned no data");
|
|
12400
|
-
}
|
|
12401
|
-
return viem.decodeFunctionResult({
|
|
12402
|
-
abi: viem.multicall3Abi,
|
|
12403
|
-
functionName: "aggregate3",
|
|
12404
|
-
data: response.data
|
|
12405
|
-
});
|
|
12406
|
-
}
|
|
12407
|
-
var PENDING_FEE_CALL_ORDER = [
|
|
12408
|
-
"collectFees",
|
|
12409
|
-
"getShares",
|
|
12410
|
-
"getCumulatedFees0",
|
|
12411
|
-
"getCumulatedFees1",
|
|
12412
|
-
"getLastCumulatedFees0",
|
|
12413
|
-
"getLastCumulatedFees1"
|
|
12380
|
+
var ABSENT_POOL_ERROR_ABI = [
|
|
12381
|
+
{ type: "error", name: "PoolNotFound", inputs: [] },
|
|
12382
|
+
{ type: "error", name: "PoolNotInitialized", inputs: [] }
|
|
12414
12383
|
];
|
|
12415
|
-
function createPendingFeePreviewCalls(target, poolId, beneficiary) {
|
|
12416
|
-
return PENDING_FEE_CALL_ORDER.map((functionName) => ({
|
|
12417
|
-
target,
|
|
12418
|
-
allowFailure: true,
|
|
12419
|
-
callData: viem.encodeFunctionData({
|
|
12420
|
-
abi: feeClaimsInitializerAbi,
|
|
12421
|
-
functionName,
|
|
12422
|
-
args: functionName === "collectFees" || functionName === "getCumulatedFees0" || functionName === "getCumulatedFees1" ? [poolId] : [poolId, beneficiary]
|
|
12423
|
-
})
|
|
12424
|
-
}));
|
|
12425
|
-
}
|
|
12426
|
-
function calculatePendingFees(callResults) {
|
|
12427
|
-
const preview = decodePendingFeePreview(callResults);
|
|
12428
|
-
if (preview.cumulatedFees0 < preview.lastCumulatedFees0) {
|
|
12429
|
-
throw new Error("Accumulated fees are below beneficiary checkpoint");
|
|
12430
|
-
}
|
|
12431
|
-
if (preview.cumulatedFees1 < preview.lastCumulatedFees1) {
|
|
12432
|
-
throw new Error("Accumulated fees are below beneficiary checkpoint");
|
|
12433
|
-
}
|
|
12434
|
-
return {
|
|
12435
|
-
fees0: (preview.cumulatedFees0 - preview.lastCumulatedFees0) * preview.shares / WAD,
|
|
12436
|
-
fees1: (preview.cumulatedFees1 - preview.lastCumulatedFees1) * preview.shares / WAD
|
|
12437
|
-
};
|
|
12438
|
-
}
|
|
12439
|
-
function decodePendingFeePreview(callResults) {
|
|
12440
|
-
if (callResults.length !== PENDING_FEE_CALL_ORDER.length) {
|
|
12441
|
-
throw new Error("Multicall3 aggregate3 returned an incomplete pool result");
|
|
12442
|
-
}
|
|
12443
|
-
for (const [index, result] of callResults.entries()) {
|
|
12444
|
-
const functionName = PENDING_FEE_CALL_ORDER[index];
|
|
12445
|
-
if (!result.success) {
|
|
12446
|
-
throw new Error(`${functionName} call failed`);
|
|
12447
|
-
}
|
|
12448
|
-
if (!result.returnData || result.returnData === "0x") {
|
|
12449
|
-
throw new Error(`${functionName} returned no data`);
|
|
12450
|
-
}
|
|
12451
|
-
}
|
|
12452
|
-
viem.decodeFunctionResult({
|
|
12453
|
-
abi: feeClaimsInitializerAbi,
|
|
12454
|
-
functionName: "collectFees",
|
|
12455
|
-
data: callResults[0].returnData
|
|
12456
|
-
});
|
|
12457
|
-
return {
|
|
12458
|
-
shares: decodeUint256("getShares", callResults[1].returnData),
|
|
12459
|
-
cumulatedFees0: decodeUint256(
|
|
12460
|
-
"getCumulatedFees0",
|
|
12461
|
-
callResults[2].returnData
|
|
12462
|
-
),
|
|
12463
|
-
cumulatedFees1: decodeUint256(
|
|
12464
|
-
"getCumulatedFees1",
|
|
12465
|
-
callResults[3].returnData
|
|
12466
|
-
),
|
|
12467
|
-
lastCumulatedFees0: decodeUint256(
|
|
12468
|
-
"getLastCumulatedFees0",
|
|
12469
|
-
callResults[4].returnData
|
|
12470
|
-
),
|
|
12471
|
-
lastCumulatedFees1: decodeUint256(
|
|
12472
|
-
"getLastCumulatedFees1",
|
|
12473
|
-
callResults[5].returnData
|
|
12474
|
-
)
|
|
12475
|
-
};
|
|
12476
|
-
}
|
|
12477
|
-
function decodeUint256(functionName, data) {
|
|
12478
|
-
const value = viem.decodeFunctionResult({
|
|
12479
|
-
abi: feeClaimsInitializerAbi,
|
|
12480
|
-
functionName,
|
|
12481
|
-
data
|
|
12482
|
-
});
|
|
12483
|
-
if (typeof value !== "bigint") {
|
|
12484
|
-
throw new Error(`${functionName} returned invalid data`);
|
|
12485
|
-
}
|
|
12486
|
-
return value;
|
|
12487
|
-
}
|
|
12488
12384
|
async function findMulticurveInitializerForPool({
|
|
12489
12385
|
client,
|
|
12490
12386
|
tokenAddress,
|
|
12491
12387
|
addresses
|
|
12492
12388
|
}) {
|
|
12493
|
-
const initializersToTry =
|
|
12389
|
+
const initializersToTry = getMulticurveInitializerCandidates(addresses);
|
|
12494
12390
|
if (initializersToTry.length === 0) {
|
|
12495
12391
|
throw new Error(
|
|
12496
12392
|
"No V4 multicurve initializer addresses configured for this chain"
|
|
@@ -12505,7 +12401,7 @@ async function findMulticurveInitializerForPool({
|
|
|
12505
12401
|
try {
|
|
12506
12402
|
stateData = await client.readContract({
|
|
12507
12403
|
address: initializerAddress,
|
|
12508
|
-
abi: kind
|
|
12404
|
+
abi: getMulticurveInitializerAbi(kind),
|
|
12509
12405
|
functionName: "getState",
|
|
12510
12406
|
args: [tokenAddress]
|
|
12511
12407
|
});
|
|
@@ -12519,21 +12415,14 @@ async function findMulticurveInitializerForPool({
|
|
|
12519
12415
|
);
|
|
12520
12416
|
continue;
|
|
12521
12417
|
}
|
|
12522
|
-
const
|
|
12523
|
-
|
|
12524
|
-
|
|
12525
|
-
|
|
12526
|
-
|
|
12527
|
-
|
|
12528
|
-
|
|
12529
|
-
|
|
12530
|
-
fee: poolKey.fee,
|
|
12531
|
-
tickSpacing: poolKey.tickSpacing,
|
|
12532
|
-
status,
|
|
12533
|
-
poolKey,
|
|
12534
|
-
farTick: Number(farTick)
|
|
12535
|
-
}
|
|
12536
|
-
};
|
|
12418
|
+
const discoveryResult = parseMulticurveInitializerDiscoveryResult({
|
|
12419
|
+
tokenAddress,
|
|
12420
|
+
initializerAddress,
|
|
12421
|
+
kind,
|
|
12422
|
+
stateData
|
|
12423
|
+
});
|
|
12424
|
+
if (isInitializedMulticurvePoolKey(discoveryResult.state.poolKey)) {
|
|
12425
|
+
return discoveryResult;
|
|
12537
12426
|
}
|
|
12538
12427
|
}
|
|
12539
12428
|
const notFoundError = new Error(
|
|
@@ -12557,7 +12446,7 @@ function parseMulticurvePoolKey(rawPoolKey) {
|
|
|
12557
12446
|
hooks: poolKeyStruct.hooks ?? poolKeyStruct[4]
|
|
12558
12447
|
};
|
|
12559
12448
|
}
|
|
12560
|
-
function
|
|
12449
|
+
function getMulticurveInitializerCandidates(addresses) {
|
|
12561
12450
|
return [
|
|
12562
12451
|
{
|
|
12563
12452
|
address: addresses.v4MulticurveInitializer,
|
|
@@ -12579,6 +12468,50 @@ function getInitializerCandidates(addresses) {
|
|
|
12579
12468
|
(entry) => Boolean(entry.address && entry.address !== viem.zeroAddress)
|
|
12580
12469
|
);
|
|
12581
12470
|
}
|
|
12471
|
+
function getMulticurveInitializerAbi(kind) {
|
|
12472
|
+
return kind === "dopplerHook" ? dopplerHookInitializerAbi : v4MulticurveInitializerAbi;
|
|
12473
|
+
}
|
|
12474
|
+
function parseMulticurveInitializerDiscoveryResult({
|
|
12475
|
+
tokenAddress,
|
|
12476
|
+
initializerAddress,
|
|
12477
|
+
kind,
|
|
12478
|
+
stateData
|
|
12479
|
+
}) {
|
|
12480
|
+
const parsedState = kind === "dopplerHook" ? parseDopplerHookInitializerState(stateData) : parseStandardInitializerState(stateData);
|
|
12481
|
+
const { numeraire, status, poolKey, farTick } = parsedState;
|
|
12482
|
+
return {
|
|
12483
|
+
initializerAddress,
|
|
12484
|
+
state: {
|
|
12485
|
+
asset: tokenAddress,
|
|
12486
|
+
numeraire,
|
|
12487
|
+
fee: poolKey.fee,
|
|
12488
|
+
tickSpacing: poolKey.tickSpacing,
|
|
12489
|
+
status,
|
|
12490
|
+
poolKey,
|
|
12491
|
+
farTick: Number(farTick)
|
|
12492
|
+
}
|
|
12493
|
+
};
|
|
12494
|
+
}
|
|
12495
|
+
function isInitializedMulticurvePoolKey(poolKey) {
|
|
12496
|
+
return poolKey.hooks !== viem.zeroAddress && poolKey.tickSpacing !== 0;
|
|
12497
|
+
}
|
|
12498
|
+
function isAbsentPoolRevertData(data) {
|
|
12499
|
+
if (data === "0x") {
|
|
12500
|
+
return false;
|
|
12501
|
+
}
|
|
12502
|
+
try {
|
|
12503
|
+
const decodedError = viem.decodeErrorResult({
|
|
12504
|
+
abi: ABSENT_POOL_ERROR_ABI,
|
|
12505
|
+
data
|
|
12506
|
+
});
|
|
12507
|
+
return decodedError.errorName === "PoolNotFound" || decodedError.errorName === "PoolNotInitialized";
|
|
12508
|
+
} catch (error) {
|
|
12509
|
+
if (error instanceof Error) {
|
|
12510
|
+
return false;
|
|
12511
|
+
}
|
|
12512
|
+
throw error;
|
|
12513
|
+
}
|
|
12514
|
+
}
|
|
12582
12515
|
function parseStandardInitializerState(stateData) {
|
|
12583
12516
|
const state = stateData;
|
|
12584
12517
|
return {
|
|
@@ -12704,6 +12637,288 @@ function readStructField(value, fieldName, tupleIndex) {
|
|
|
12704
12637
|
}
|
|
12705
12638
|
return 0;
|
|
12706
12639
|
}
|
|
12640
|
+
function getMulticall3Address(client) {
|
|
12641
|
+
const multicall3Address = client.chain?.contracts?.multicall3?.address;
|
|
12642
|
+
if (!multicall3Address || multicall3Address === viem.zeroAddress) {
|
|
12643
|
+
throw new Error(
|
|
12644
|
+
"Multicall3 address is not configured on this chain. Configure the viem chain multicall3 contract before previewing pending fees."
|
|
12645
|
+
);
|
|
12646
|
+
}
|
|
12647
|
+
return multicall3Address;
|
|
12648
|
+
}
|
|
12649
|
+
async function callAggregate3(client, calls) {
|
|
12650
|
+
const response = await client.call({
|
|
12651
|
+
to: getMulticall3Address(client),
|
|
12652
|
+
data: viem.encodeFunctionData({
|
|
12653
|
+
abi: viem.multicall3Abi,
|
|
12654
|
+
functionName: "aggregate3",
|
|
12655
|
+
args: [calls]
|
|
12656
|
+
})
|
|
12657
|
+
});
|
|
12658
|
+
if (!response.data) {
|
|
12659
|
+
throw new Error("Multicall3 aggregate3 returned no data");
|
|
12660
|
+
}
|
|
12661
|
+
return viem.decodeFunctionResult({
|
|
12662
|
+
abi: viem.multicall3Abi,
|
|
12663
|
+
functionName: "aggregate3",
|
|
12664
|
+
data: response.data
|
|
12665
|
+
});
|
|
12666
|
+
}
|
|
12667
|
+
var PENDING_FEE_CALL_ORDER = [
|
|
12668
|
+
"collectFees",
|
|
12669
|
+
"getShares",
|
|
12670
|
+
"getCumulatedFees0",
|
|
12671
|
+
"getCumulatedFees1",
|
|
12672
|
+
"getLastCumulatedFees0",
|
|
12673
|
+
"getLastCumulatedFees1"
|
|
12674
|
+
];
|
|
12675
|
+
var PENDING_FEE_PREVIEW_CALL_COUNT = PENDING_FEE_CALL_ORDER.length;
|
|
12676
|
+
function createPendingFeePreviewCalls(target, poolId, beneficiary) {
|
|
12677
|
+
return PENDING_FEE_CALL_ORDER.map((functionName) => ({
|
|
12678
|
+
target,
|
|
12679
|
+
allowFailure: true,
|
|
12680
|
+
callData: viem.encodeFunctionData({
|
|
12681
|
+
abi: feeClaimsInitializerAbi,
|
|
12682
|
+
functionName,
|
|
12683
|
+
args: functionName === "collectFees" || functionName === "getCumulatedFees0" || functionName === "getCumulatedFees1" ? [poolId] : [poolId, beneficiary]
|
|
12684
|
+
})
|
|
12685
|
+
}));
|
|
12686
|
+
}
|
|
12687
|
+
function calculatePendingFees(callResults) {
|
|
12688
|
+
const preview = decodePendingFeePreview(callResults);
|
|
12689
|
+
if (preview.cumulatedFees0 < preview.lastCumulatedFees0) {
|
|
12690
|
+
throw new Error("Accumulated fees are below beneficiary checkpoint");
|
|
12691
|
+
}
|
|
12692
|
+
if (preview.cumulatedFees1 < preview.lastCumulatedFees1) {
|
|
12693
|
+
throw new Error("Accumulated fees are below beneficiary checkpoint");
|
|
12694
|
+
}
|
|
12695
|
+
return {
|
|
12696
|
+
fees0: (preview.cumulatedFees0 - preview.lastCumulatedFees0) * preview.shares / WAD,
|
|
12697
|
+
fees1: (preview.cumulatedFees1 - preview.lastCumulatedFees1) * preview.shares / WAD
|
|
12698
|
+
};
|
|
12699
|
+
}
|
|
12700
|
+
function decodePendingFeePreview(callResults) {
|
|
12701
|
+
if (callResults.length !== PENDING_FEE_CALL_ORDER.length) {
|
|
12702
|
+
throw new Error("Multicall3 aggregate3 returned an incomplete pool result");
|
|
12703
|
+
}
|
|
12704
|
+
for (const [index, result] of callResults.entries()) {
|
|
12705
|
+
const functionName = PENDING_FEE_CALL_ORDER[index];
|
|
12706
|
+
if (!result.success) {
|
|
12707
|
+
throw new Error(`${functionName} call failed`);
|
|
12708
|
+
}
|
|
12709
|
+
if (!result.returnData || result.returnData === "0x") {
|
|
12710
|
+
throw new Error(`${functionName} returned no data`);
|
|
12711
|
+
}
|
|
12712
|
+
}
|
|
12713
|
+
viem.decodeFunctionResult({
|
|
12714
|
+
abi: feeClaimsInitializerAbi,
|
|
12715
|
+
functionName: "collectFees",
|
|
12716
|
+
data: callResults[0].returnData
|
|
12717
|
+
});
|
|
12718
|
+
return {
|
|
12719
|
+
shares: decodeUint256("getShares", callResults[1].returnData),
|
|
12720
|
+
cumulatedFees0: decodeUint256(
|
|
12721
|
+
"getCumulatedFees0",
|
|
12722
|
+
callResults[2].returnData
|
|
12723
|
+
),
|
|
12724
|
+
cumulatedFees1: decodeUint256(
|
|
12725
|
+
"getCumulatedFees1",
|
|
12726
|
+
callResults[3].returnData
|
|
12727
|
+
),
|
|
12728
|
+
lastCumulatedFees0: decodeUint256(
|
|
12729
|
+
"getLastCumulatedFees0",
|
|
12730
|
+
callResults[4].returnData
|
|
12731
|
+
),
|
|
12732
|
+
lastCumulatedFees1: decodeUint256(
|
|
12733
|
+
"getLastCumulatedFees1",
|
|
12734
|
+
callResults[5].returnData
|
|
12735
|
+
)
|
|
12736
|
+
};
|
|
12737
|
+
}
|
|
12738
|
+
function decodeUint256(functionName, data) {
|
|
12739
|
+
const value = viem.decodeFunctionResult({
|
|
12740
|
+
abi: feeClaimsInitializerAbi,
|
|
12741
|
+
functionName,
|
|
12742
|
+
data
|
|
12743
|
+
});
|
|
12744
|
+
if (typeof value !== "bigint") {
|
|
12745
|
+
throw new Error(`${functionName} returned invalid data`);
|
|
12746
|
+
}
|
|
12747
|
+
return value;
|
|
12748
|
+
}
|
|
12749
|
+
|
|
12750
|
+
// src/evm/entities/auction/multicurve/multicurvePendingFeeReader.ts
|
|
12751
|
+
async function getPendingFeesForMulticurvePool({
|
|
12752
|
+
client,
|
|
12753
|
+
beneficiary,
|
|
12754
|
+
poolContext
|
|
12755
|
+
}) {
|
|
12756
|
+
const pendingFees = await getPendingFeesForDiscoveredMulticurvePools({
|
|
12757
|
+
client,
|
|
12758
|
+
beneficiary,
|
|
12759
|
+
poolContexts: [poolContext]
|
|
12760
|
+
});
|
|
12761
|
+
const poolPendingFees = pendingFees[0];
|
|
12762
|
+
if (!poolPendingFees) {
|
|
12763
|
+
throw new Error("Pending fee preview returned no pool result");
|
|
12764
|
+
}
|
|
12765
|
+
return {
|
|
12766
|
+
fees0: poolPendingFees.fees0,
|
|
12767
|
+
fees1: poolPendingFees.fees1
|
|
12768
|
+
};
|
|
12769
|
+
}
|
|
12770
|
+
async function getPendingFeesForMulticurveTokens({
|
|
12771
|
+
client,
|
|
12772
|
+
beneficiary,
|
|
12773
|
+
tokenAddresses
|
|
12774
|
+
}) {
|
|
12775
|
+
if (tokenAddresses.length === 0) {
|
|
12776
|
+
return [];
|
|
12777
|
+
}
|
|
12778
|
+
const feeClient = client;
|
|
12779
|
+
const poolContexts = await discoverMulticurveFeePoolContexts(
|
|
12780
|
+
feeClient,
|
|
12781
|
+
tokenAddresses
|
|
12782
|
+
);
|
|
12783
|
+
return getPendingFeesForDiscoveredMulticurvePools({
|
|
12784
|
+
client: feeClient,
|
|
12785
|
+
beneficiary,
|
|
12786
|
+
poolContexts
|
|
12787
|
+
});
|
|
12788
|
+
}
|
|
12789
|
+
async function discoverMulticurveFeePoolContexts(client, tokenAddresses) {
|
|
12790
|
+
const chainId = await client.getChainId();
|
|
12791
|
+
const addresses = getAddresses(chainId);
|
|
12792
|
+
const initializers = getMulticurveInitializerCandidates(addresses);
|
|
12793
|
+
if (initializers.length === 0) {
|
|
12794
|
+
throw new Error(
|
|
12795
|
+
"No V4 multicurve initializer addresses configured for this chain"
|
|
12796
|
+
);
|
|
12797
|
+
}
|
|
12798
|
+
const discoveryContexts = createDiscoveryCallContexts(
|
|
12799
|
+
tokenAddresses,
|
|
12800
|
+
initializers
|
|
12801
|
+
);
|
|
12802
|
+
const discoveryResults = await callAggregate3(
|
|
12803
|
+
client,
|
|
12804
|
+
createDiscoveryCalls(discoveryContexts)
|
|
12805
|
+
);
|
|
12806
|
+
if (discoveryResults.length !== discoveryContexts.length) {
|
|
12807
|
+
throw new Error(
|
|
12808
|
+
"Multicall3 aggregate3 returned an incomplete initializer discovery result"
|
|
12809
|
+
);
|
|
12810
|
+
}
|
|
12811
|
+
return tokenAddresses.map(
|
|
12812
|
+
(tokenAddress, tokenIndex) => findInitializedPoolForToken({
|
|
12813
|
+
tokenAddress,
|
|
12814
|
+
initializers,
|
|
12815
|
+
discoveryResults: discoveryResults.slice(
|
|
12816
|
+
tokenIndex * initializers.length,
|
|
12817
|
+
(tokenIndex + 1) * initializers.length
|
|
12818
|
+
)
|
|
12819
|
+
})
|
|
12820
|
+
);
|
|
12821
|
+
}
|
|
12822
|
+
function createDiscoveryCallContexts(tokenAddresses, initializers) {
|
|
12823
|
+
return tokenAddresses.flatMap(
|
|
12824
|
+
(tokenAddress) => initializers.map((initializer) => ({
|
|
12825
|
+
tokenAddress,
|
|
12826
|
+
initializer
|
|
12827
|
+
}))
|
|
12828
|
+
);
|
|
12829
|
+
}
|
|
12830
|
+
function createDiscoveryCalls(contexts) {
|
|
12831
|
+
return contexts.map(({ tokenAddress, initializer }) => ({
|
|
12832
|
+
target: initializer.address,
|
|
12833
|
+
allowFailure: true,
|
|
12834
|
+
callData: viem.encodeFunctionData({
|
|
12835
|
+
abi: getMulticurveInitializerAbi(initializer.kind),
|
|
12836
|
+
functionName: "getState",
|
|
12837
|
+
args: [tokenAddress]
|
|
12838
|
+
})
|
|
12839
|
+
}));
|
|
12840
|
+
}
|
|
12841
|
+
function findInitializedPoolForToken({
|
|
12842
|
+
tokenAddress,
|
|
12843
|
+
initializers,
|
|
12844
|
+
discoveryResults
|
|
12845
|
+
}) {
|
|
12846
|
+
for (const [index, result] of discoveryResults.entries()) {
|
|
12847
|
+
const initializer = initializers[index];
|
|
12848
|
+
if (!initializer) {
|
|
12849
|
+
throw new Error(
|
|
12850
|
+
"Multicall3 aggregate3 returned an incomplete initializer discovery result"
|
|
12851
|
+
);
|
|
12852
|
+
}
|
|
12853
|
+
if (!result.success) {
|
|
12854
|
+
if (isAbsentPoolRevertData(result.returnData)) {
|
|
12855
|
+
continue;
|
|
12856
|
+
}
|
|
12857
|
+
throw new Error(
|
|
12858
|
+
`${initializer.address} getState failed for token ${tokenAddress}`
|
|
12859
|
+
);
|
|
12860
|
+
}
|
|
12861
|
+
if (!result.returnData || result.returnData === "0x") {
|
|
12862
|
+
throw new Error(
|
|
12863
|
+
`${initializer.address} getState returned no data for token ${tokenAddress}`
|
|
12864
|
+
);
|
|
12865
|
+
}
|
|
12866
|
+
const discoveryResult = parseMulticurveInitializerDiscoveryResult({
|
|
12867
|
+
tokenAddress,
|
|
12868
|
+
initializerAddress: initializer.address,
|
|
12869
|
+
kind: initializer.kind,
|
|
12870
|
+
stateData: viem.decodeFunctionResult({
|
|
12871
|
+
abi: getMulticurveInitializerAbi(initializer.kind),
|
|
12872
|
+
functionName: "getState",
|
|
12873
|
+
data: result.returnData
|
|
12874
|
+
})
|
|
12875
|
+
});
|
|
12876
|
+
if (isInitializedMulticurvePoolKey(discoveryResult.state.poolKey)) {
|
|
12877
|
+
assertPendingFeePreviewable(discoveryResult);
|
|
12878
|
+
return discoveryResult;
|
|
12879
|
+
}
|
|
12880
|
+
}
|
|
12881
|
+
throw new Error(
|
|
12882
|
+
`Pool not found for token ${tokenAddress}. Tried initializers: ${initializers.map((initializer) => initializer.address).join(", ")}`
|
|
12883
|
+
);
|
|
12884
|
+
}
|
|
12885
|
+
function assertPendingFeePreviewable(discoveryResult) {
|
|
12886
|
+
const { asset, status } = discoveryResult.state;
|
|
12887
|
+
if (status === 3 /* Exited */) {
|
|
12888
|
+
throw new Error(
|
|
12889
|
+
`Pending fee preview is only supported for initializer-side multicurve pools: ${asset}`
|
|
12890
|
+
);
|
|
12891
|
+
}
|
|
12892
|
+
if (status !== 2 /* Locked */) {
|
|
12893
|
+
throw new Error(`Multicurve pool is not locked or was migrated: ${asset}`);
|
|
12894
|
+
}
|
|
12895
|
+
}
|
|
12896
|
+
async function getPendingFeesForDiscoveredMulticurvePools({
|
|
12897
|
+
client,
|
|
12898
|
+
beneficiary,
|
|
12899
|
+
poolContexts
|
|
12900
|
+
}) {
|
|
12901
|
+
for (const poolContext of poolContexts) {
|
|
12902
|
+
assertPendingFeePreviewable(poolContext);
|
|
12903
|
+
}
|
|
12904
|
+
const previewCalls = poolContexts.flatMap(
|
|
12905
|
+
({ initializerAddress, state }) => createPendingFeePreviewCalls(
|
|
12906
|
+
initializerAddress,
|
|
12907
|
+
computePoolId(state.poolKey),
|
|
12908
|
+
beneficiary
|
|
12909
|
+
)
|
|
12910
|
+
);
|
|
12911
|
+
const previewResults = await callAggregate3(client, previewCalls);
|
|
12912
|
+
return poolContexts.map(({ state }, index) => ({
|
|
12913
|
+
tokenAddress: state.asset,
|
|
12914
|
+
...calculatePendingFees(
|
|
12915
|
+
previewResults.slice(
|
|
12916
|
+
index * PENDING_FEE_PREVIEW_CALL_COUNT,
|
|
12917
|
+
(index + 1) * PENDING_FEE_PREVIEW_CALL_COUNT
|
|
12918
|
+
)
|
|
12919
|
+
)
|
|
12920
|
+
}));
|
|
12921
|
+
}
|
|
12707
12922
|
|
|
12708
12923
|
// src/evm/entities/auction/MulticurvePool.ts
|
|
12709
12924
|
var MulticurvePool = class {
|
|
@@ -12782,21 +12997,11 @@ var MulticurvePool = class {
|
|
|
12782
12997
|
* Preview pending fees for a beneficiary on an initializer-side multicurve pool.
|
|
12783
12998
|
*/
|
|
12784
12999
|
async getPendingFees(beneficiary) {
|
|
12785
|
-
|
|
12786
|
-
|
|
12787
|
-
|
|
12788
|
-
|
|
12789
|
-
|
|
12790
|
-
}
|
|
12791
|
-
if (state.status !== 2 /* Locked */) {
|
|
12792
|
-
throw new Error("Multicurve pool is not locked or was migrated");
|
|
12793
|
-
}
|
|
12794
|
-
const poolId = computePoolId(state.poolKey);
|
|
12795
|
-
const callResults = await callAggregate3(
|
|
12796
|
-
this.rpc,
|
|
12797
|
-
createPendingFeePreviewCalls(initializerAddress, poolId, beneficiary)
|
|
12798
|
-
);
|
|
12799
|
-
return calculatePendingFees(callResults);
|
|
13000
|
+
return getPendingFeesForMulticurvePool({
|
|
13001
|
+
client: this.rpc,
|
|
13002
|
+
beneficiary,
|
|
13003
|
+
poolContext: await this.findInitializerForPool()
|
|
13004
|
+
});
|
|
12800
13005
|
}
|
|
12801
13006
|
/**
|
|
12802
13007
|
* Get the numeraire address for this pool
|
|
@@ -12816,6 +13021,55 @@ var MulticurvePool = class {
|
|
|
12816
13021
|
}
|
|
12817
13022
|
};
|
|
12818
13023
|
|
|
13024
|
+
// src/evm/entities/auction/MulticurveFees.ts
|
|
13025
|
+
var MulticurveFees = class {
|
|
13026
|
+
client;
|
|
13027
|
+
tokenAddresses;
|
|
13028
|
+
options;
|
|
13029
|
+
constructor(client, _walletClient, tokenAddresses, options = {}) {
|
|
13030
|
+
this.client = client;
|
|
13031
|
+
this.tokenAddresses = [...tokenAddresses];
|
|
13032
|
+
this.options = { ...options };
|
|
13033
|
+
}
|
|
13034
|
+
async getPendingFees(beneficiary, tokenAddressesOrOptions, options) {
|
|
13035
|
+
const hasTokenAddressOverride = isTokenAddressList(tokenAddressesOrOptions);
|
|
13036
|
+
const tokenAddresses = hasTokenAddressOverride ? tokenAddressesOrOptions : this.tokenAddresses;
|
|
13037
|
+
const callOptions = hasTokenAddressOverride ? options : tokenAddressesOrOptions;
|
|
13038
|
+
const tokenBatchSize = getTokenBatchSize(
|
|
13039
|
+
callOptions?.tokenBatchSize ?? this.options.tokenBatchSize
|
|
13040
|
+
);
|
|
13041
|
+
if (!tokenBatchSize || tokenAddresses.length <= tokenBatchSize) {
|
|
13042
|
+
return getPendingFeesForMulticurveTokens({
|
|
13043
|
+
client: this.client,
|
|
13044
|
+
beneficiary,
|
|
13045
|
+
tokenAddresses
|
|
13046
|
+
});
|
|
13047
|
+
}
|
|
13048
|
+
let pendingFees = [];
|
|
13049
|
+
for (let index = 0; index < tokenAddresses.length; index += tokenBatchSize) {
|
|
13050
|
+
const batchPendingFees = await getPendingFeesForMulticurveTokens({
|
|
13051
|
+
client: this.client,
|
|
13052
|
+
beneficiary,
|
|
13053
|
+
tokenAddresses: tokenAddresses.slice(index, index + tokenBatchSize)
|
|
13054
|
+
});
|
|
13055
|
+
pendingFees = [...pendingFees, ...batchPendingFees];
|
|
13056
|
+
}
|
|
13057
|
+
return pendingFees;
|
|
13058
|
+
}
|
|
13059
|
+
};
|
|
13060
|
+
function isTokenAddressList(value) {
|
|
13061
|
+
return Array.isArray(value);
|
|
13062
|
+
}
|
|
13063
|
+
function getTokenBatchSize(tokenBatchSize) {
|
|
13064
|
+
if (tokenBatchSize === void 0) {
|
|
13065
|
+
return void 0;
|
|
13066
|
+
}
|
|
13067
|
+
if (!Number.isInteger(tokenBatchSize) || tokenBatchSize < 1) {
|
|
13068
|
+
throw new Error("tokenBatchSize must be a positive integer");
|
|
13069
|
+
}
|
|
13070
|
+
return tokenBatchSize;
|
|
13071
|
+
}
|
|
13072
|
+
|
|
12819
13073
|
// src/evm/entities/auction/RehypeDopplerHook.ts
|
|
12820
13074
|
var RehypeDopplerHook = class {
|
|
12821
13075
|
client;
|
|
@@ -19058,6 +19312,7 @@ exports.MAX_TICK = MAX_TICK;
|
|
|
19058
19312
|
exports.MIN_SQRT_RATIO = MIN_SQRT_RATIO;
|
|
19059
19313
|
exports.MIN_TICK = MIN_TICK;
|
|
19060
19314
|
exports.MulticurveBuilder = MulticurveBuilder;
|
|
19315
|
+
exports.MulticurveFees = MulticurveFees;
|
|
19061
19316
|
exports.MulticurvePool = MulticurvePool;
|
|
19062
19317
|
exports.NO_OP_ENABLED_CHAIN_IDS = NO_OP_ENABLED_CHAIN_IDS;
|
|
19063
19318
|
exports.OPENING_AUCTION_FLAGS = OPENING_AUCTION_FLAGS;
|