fix: dex aggregator bridge-fee estimation

This commit is contained in:
c4605
2025-04-13 12:41:24 +02:00
parent f95f263e76
commit 6042d0f27d
5 changed files with 93 additions and 9 deletions

View File

@@ -143,7 +143,21 @@ export const getStacks2BtcFeeInfo = async (
route: KnownRoute_FromStacks_ToBitcoin,
options: {
/**
* the initial route step
* The entry route step that triggered the Stacks transaction.
* It's crucial for correctly calculating fees in multi-step bridging
* processes.
*
* Examples:
*
* * BTC > Runes (`via: ALEX`):
* 1. btc > stacks (initialRoute)
* 2. stacks > runes
* * BTC > Runes (`via: evmDexAggregator`):
* 1. btc > stacks (initialRoute as well, but not what we want)
* 2. stacks > evm
* 3. evm swap
* 4. evm > stacks (initialRoute for this partition)
* 5. stacks > runes
*/
initialRoute: null | KnownRoute_ToStacks
/**
@@ -169,7 +183,21 @@ const _getStacks2BtcFeeInfo = async (
route: KnownRoute_FromStacks_ToBitcoin,
options: {
/**
* the initial route step
* The entry route step that triggered the Stacks transaction.
* It's crucial for correctly calculating fees in multi-step bridging
* processes.
*
* Examples:
*
* * BTC > Runes (`via: ALEX`):
* 1. btc > stacks (initialRoute)
* 2. stacks > runes
* * BTC > Runes (`via: evmDexAggregator`):
* 1. btc > stacks (initialRoute as well, but not what we want)
* 2. stacks > evm
* 3. evm swap
* 4. evm > stacks (initialRoute for this partition)
* 5. stacks > runes
*/
initialRoute: null | KnownRoute_ToStacks
/**

View File

@@ -237,7 +237,21 @@ export const getStacks2EvmFeeInfo = async (
options: {
toDexAggregator: boolean
/**
* checkout the comments in getSpecialFeeDetailsForSwapRoute
* The entry route step that triggered the Stacks transaction.
* It's crucial for correctly calculating fees in multi-step bridging
* processes.
*
* Examples:
*
* * BTC > Runes (`via: ALEX`):
* 1. btc > stacks (initialRoute)
* 2. stacks > runes
* * BTC > Runes (`via: evmDexAggregator`):
* 1. btc > stacks (initialRoute as well, but not what we want)
* 2. stacks > evm
* 3. evm swap
* 4. evm > stacks (initialRoute for this partition)
* 5. stacks > runes
*/
initialRoute: null | KnownRoute_ToStacks
},
@@ -260,7 +274,21 @@ const _getStacks2EvmFeeInfo = async (
options: {
toDexAggregator: boolean
/**
* checkout the comments in getSpecialFeeDetailsForSwapRoute
* The entry route step that triggered the Stacks transaction.
* It's crucial for correctly calculating fees in multi-step bridging
* processes.
*
* Examples:
*
* * BTC > Runes (`via: ALEX`):
* 1. btc > stacks (initialRoute)
* 2. stacks > runes
* * BTC > Runes (`via: evmDexAggregator`):
* 1. btc > stacks (initialRoute as well, but not what we want)
* 2. stacks > evm
* 3. evm swap
* 4. evm > stacks (initialRoute for this partition)
* 5. stacks > runes
*/
initialRoute: null | KnownRoute_ToStacks
},

View File

@@ -226,7 +226,21 @@ export const getStacks2MetaFeeInfo = async (
route: KnownRoute_FromStacks_ToBRC20 | KnownRoute_FromStacks_ToRunes,
options: {
/**
* the initial route step
* The entry route step that triggered the Stacks transaction.
* It's crucial for correctly calculating fees in multi-step bridging
* processes.
*
* Examples:
*
* * BTC > Runes (`via: ALEX`):
* 1. btc > stacks (initialRoute)
* 2. stacks > runes
* * BTC > Runes (`via: evmDexAggregator`):
* 1. btc > stacks (initialRoute as well, but not what we want)
* 2. stacks > evm
* 3. evm swap
* 4. evm > stacks (initialRoute for this partition)
* 5. stacks > runes
*/
initialRoute: null | KnownRoute_ToStacks
/**
@@ -252,7 +266,21 @@ const _getStacks2MetaFeeInfo = async (
route: KnownRoute_FromStacks_ToBRC20 | KnownRoute_FromStacks_ToRunes,
options: {
/**
* the initial route step
* The entry route step that triggered the Stacks transaction.
* It's crucial for correctly calculating fees in multi-step bridging
* processes.
*
* Examples:
*
* * BTC > Runes (`via: ALEX`):
* 1. btc > stacks (initialRoute)
* 2. stacks > runes
* * BTC > Runes (`via: evmDexAggregator`):
* 1. btc > stacks (initialRoute as well, but not what we want)
* 2. stacks > evm
* 3. evm swap
* 4. evm > stacks (initialRoute for this partition)
* 5. stacks > runes
*/
initialRoute: null | KnownRoute_ToStacks
/**

View File

@@ -513,7 +513,7 @@ async function bridgeInfoFromBitcoin_toMeta(
}),
...intermediaryInfo.steps,
getStacks2MetaFeeInfo(ctx, metaPegOutRoute as any, {
initialRoute: btcPegInRoute,
initialRoute: last(intermediaryInfo.routes) as KnownRoute_ToStacks,
swapRoute: null,
}),
])

View File

@@ -622,7 +622,7 @@ async function bridgeInfoFromMeta_toBitcoin(
}),
...intermediaryInfo.steps,
getStacks2BtcFeeInfo(ctx, btcPegOutRoute, {
initialRoute: metaPegInRoute,
initialRoute: last(intermediaryInfo.routes) as KnownRoute_ToStacks,
swapRoute: null,
}),
])
@@ -782,7 +782,7 @@ async function bridgeInfoFromMeta_toMeta(
}),
...intermediaryInfo.steps,
getStacks2MetaFeeInfo(ctx, metaPegOutRoute, {
initialRoute: metaPegInRoute,
initialRoute: last(intermediaryInfo.routes) as KnownRoute_ToStacks,
swapRoute: null,
}),
])