Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update fixed-point-wasm #1351

Closed
ryangoree opened this issue Aug 13, 2024 · 2 comments · Fixed by #1398
Closed

Update fixed-point-wasm #1351

ryangoree opened this issue Aug 13, 2024 · 2 comments · Fixed by #1398
Assignees
Labels
enhancement New feature or request hyperdrive-js tech debt Code cleanup task

Comments

@ryangoree
Copy link
Member

Support for negative numbers just landed in delvtech/hyperdrive-rs#186. The wrappers should be updated to avoid bugs from accidentally passing a negative number to the lib and any special handling of negative numbers should be cleaned up. For example:

const [sign, abs] = rate >= 0n ? ["", rate] : ["-", -rate];
return `${sign}${fixed(abs, decimals).format({
percent: true,
decimals: 2,
rounding: "trunc",
})}`;

@ryangoree ryangoree self-assigned this Aug 13, 2024
@ryangoree ryangoree added enhancement New feature or request tech debt Code cleanup task hyperdrive-js labels Aug 13, 2024
@ryangoree
Copy link
Member Author

ryangoree commented Aug 21, 2024

Ran into a few gotchas integrating the generic FixedPoint type into the lib. One of them has been resolved via rustwasm/wasm-bindgen#4082, but I'm still working through the rest.

After some initial struggles with the bindings, I started porting everything over to TypeScript and using BigInts directly to avoid being limited by the largest signed type implemented in the fixedpointmath, I256. However, I realized the ln function is pretty cryptic and super optimized for efficiency and I think it would be better if both libs were built on the same source code rather than blindly porting it over and risking confusing errors from slight differences in how each language handles the bit operations.

I could have the TypeScript port use a binding of just the ln function, but for now I'm back to trying to make the bindings work, but with some new learnings gained while porting that will make it more efficient, easier to use, and slightly less bug prone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hyperdrive-js tech debt Code cleanup task
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant