Fee Calculation
Fee calculation
Bonder Fee
Relayer Fee
Bonder fee implementation pseudo code
bonderFee = getBonderFee(amountIn, source, destination)
getBonderFee(amountIn, source, destination, isHTokenSend) {
hTokenAmount = getToHTokenAmount(amountIn, source)
bonderFeeRelative = getBonderFeeRelative(amountIn, source, destination)
destinationTxFee = getDestinationTxFee(source, destination)
adjustedBonderFee = 0
adjustedDestinationTxFee = 0
totalFee = 0
if (source != L1) {
if (isHTokenSend) {
adjustedBonderFee = bonderFeeRelative
adjustedDestinationTxFee = destinationTxFee
} else {
adjustedBonderFee = getFromHTokenAmount(bonderFeeRelative, destination)
adjustedDestinationTxFee = getToHTokenAmount(destinationTxFee, destination)
}
bonderFeeAbsolute = getBonderFeeAbsolute()
if (adjustedBonderFee < bonderFeeAbsolute) {
adjustedBonderFee = bonderFeeAbsolute
}
totalFee = adjustedBonderFee + adjustedDestinationTxFee
}
return totalFee
}
getToHTokenAmount(amount, chain) {
if (chain == L1) {
return amount
}
canonicalTokenIndex = 0
hTokenIndex = 1
amountOut = getAmmContract(chain).calculateSwap(canonicalTokenIndex, hTokenIndex, amount)
return amountOut
}
getFromHTokenAmount(amount, chain) {
if (chain == L1) {
return amount
}
canonicalTokenIndex = 0
hTokenIndex = 1
amountOut = getAmmContract(chain).calculateSwap(hTokenIndex, canonicalTokenIndex, amount)
return amountOut
}
getBonderFeeRelative(amountIn, source, destination) {
if (source == L1) {
return 0
}
hTokenAmount = getToHTokenAmount(amountIn, source)
feeBps = getFeeBps(token, dest)
bonderFeeRelative = (hTokenAmount * feeBps) / 10000
return bonderFeeRelative
}
getBonderFeeAbsolute() {
price = getPrice(token)
minBonderFeeUsd = 0.25
bonderFeeAbsolute = (minBonderFeeUsd / price)
return bonderFeeAbsolute
}
getDestinationTxFee(source, destination) {
if (source == L1) {
return 0
}
nativeTokenPrice = getPrice(getNativeToken(destination))
tokenPrice = getPrice(token)
gasPrice = getGasPrice(destination)
bondTransferGasLimit = getEstimatedBondWithdrawalGasLimit(destination)
rate = nativeTokenPrice / tokenPrice
settlementGasLimit = getSettlementGasLimit(destination)
totalGasLimit = bondTransferGasLimit + settlementGasLimit
txFeeEth = gasPrice * totalGasLimit
fee = txFeeEth * rate
return fee
}Questions
Last updated