feat: filter out routes where the bridge amount does not appliable

This commit is contained in:
c4605
2025-04-10 23:28:01 +02:00
parent c376508cf3
commit 8cadc3bf9c

View File

@@ -178,9 +178,11 @@ async function _getEVMDexAggregatorSwapParametersImpl(
toDexAggregator: true,
initialRoute: info.initialToStacksRoute,
},
).then(info =>
info == null || info.isPaused ? null : { token, transferProphet: info },
),
).then(feeInfo => {
if (feeInfo == null) return null
if (!isTransferProphetValid(feeInfo, info.amount)) return null
return { token, transferProphet: feeInfo }
}),
),
).then(infos => infos.filter(isNotNull))
@@ -191,7 +193,13 @@ async function _getEVMDexAggregatorSwapParametersImpl(
fromToken: token,
toChain: transitStacksChain,
toToken: lastStepFromStacksToken,
}).then(info => (info == null || info.isPaused ? null : token)),
}).then(feeInfo =>
/**
* we can not compare the amount with the max/min bridge amount here,
* since we can not know the swapped amount here
*/
feeInfo == null || feeInfo.isPaused ? null : token,
),
),
).then(tokens => tokens.filter(isNotNull))
@@ -215,3 +223,26 @@ async function _getEVMDexAggregatorSwapParametersImpl(
}
return results
}
function isTransferProphetValid(
feeInfo: TransferProphet,
amount: BigNumber,
): boolean {
if (feeInfo.isPaused) return false
if (
feeInfo.minBridgeAmount != null &&
BigNumber.isLt(amount, feeInfo.minBridgeAmount)
) {
return false
}
if (
feeInfo.maxBridgeAmount != null &&
BigNumber.isGt(amount, feeInfo.maxBridgeAmount)
) {
return false
}
return true
}