prb-math icon indicating copy to clipboard operation
prb-math copied to clipboard

Console.log for the UD60x18, SD59x18 types

Open asparuhdamyanov opened this issue 1 year ago • 2 comments

Describe the feature you would like

A way to console.log for the UD60x18, SD59x18 types.

Additional context

No response

asparuhdamyanov avatar Jun 21 '24 09:06 asparuhdamyanov

Thanks @asparuhdamyanov for your feature request.

Extending things like Forge's console.log and console2.log is difficult in Solidity because Rust-like traits are not supported.

One idea is to create a bespoke prbConsole library. Users would have to import both that and the Forge library. Would this work for you?

PaulRBerg avatar Jun 21 '24 14:06 PaulRBerg

Note that in the meantime, you can unwrap the PRBMath types like so:

import { ud, unwrap } from "@prb/math/src/UD60x18.sol";
import { console2 } from "forge-std/src/console2.sol";

function testFoo() external view {
    UD60x18 x = ud(3.14e18);
    console2.log(unwrap(x));
}

or using UD60x18.unwrap(x).

PaulRBerg avatar Jun 21 '24 14:06 PaulRBerg