mirror of
https://github.com/Brotocol-xyz/bro-sdk.git
synced 2026-01-12 06:44:18 +08:00
feat: filter out routes where the bridge amount does not appliable
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user