@@ -45,8 +45,14 @@ access(all) contract UniswapV3SwapConnectors {
4545 return EVMAbiHelpers.concat (head).concat (EVMAbiHelpers.concat (tail))
4646 }
4747
48+ /// Convert an ERC20 `UInt256` amount into a Cadence `UFix64` **by rounding down** to the
49+ /// maximum `UFix64` precision (8 decimal places).
50+ ///
51+ /// - For `decimals <= 8`, the value is exactly representable, so this is a direct conversion.
52+ /// - For `decimals > 8`, this floors the ERC20 amount to the nearest multiple of
53+ /// `quantum = 10^(decimals - 8)` so the result round-trips safely:
54+ /// `ufix64ToUInt256(result) <= amt`.
4855 access (all) fun toCadenceOutWithDecimals (_ amt : UInt256 , decimals : UInt8 ): UFix64 {
49- // floor to 8 decimals if decimals > 8 by truncating to a multiple of quantum
5056 if decimals < = 8 {
5157 return FlowEVMBridgeUtils.uint256ToUFix64 (value : amt, decimals : decimals)
5258 }
@@ -59,6 +65,13 @@ access(all) contract UniswapV3SwapConnectors {
5965 return FlowEVMBridgeUtils.uint256ToUFix64 (value : floored, decimals : decimals)
6066 }
6167
68+ /// Convert an ERC20 `UInt256` amount into a Cadence `UFix64` **by rounding up** to the
69+ /// smallest representable value at `UFix64` precision (8 decimal places).
70+ ///
71+ /// - For `decimals <= 8`, the value is exactly representable, so this is a direct conversion.
72+ /// - For `decimals > 8`, this ceils the ERC20 amount to the next multiple of
73+ /// `quantum = 10^(decimals - 8)` (unless already exact), ensuring:
74+ /// `ufix64ToUInt256(result) >= amt`, and the increase is `< quantum`.
6275 access (all) fun toCadenceInWithDecimals (_ amt : UInt256 , decimals : UInt8 ): UFix64 {
6376 if decimals < = 8 {
6477 return FlowEVMBridgeUtils.uint256ToUFix64 (value : amt, decimals : decimals)
0 commit comments