Skip to content

Conversation

0xLisanAlGaib
Copy link
Contributor

No description provided.

Copy link

vercel bot commented Oct 15, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
docs Ready Ready Preview Comment Oct 15, 2025 6:04pm

let finalAmount = output / someRatio // Even more precision lost
```

After 3-4 sequential operations, the cumulative rounding error can be significant, especially when dealing with large amounts.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here though give a specific example. "After 100 operations of 1 million dollars USDF, the protocol is losing XXX,XXX in revenue from this lack of precision".


These constants ensure consistent scaling across all operations.

## Rounding Modes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smart Rounding Modes? We want to make sure Smart Rounding surfaces in search I think, so it needs to be a heading

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The section below doesn't really sound like smart rounding or explain what it is. Should the comment above be something like "Final results with rounding strategy applied"?

}
```

### When to Use Each Mode
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section is great to have but feels a little light. Can you please add a sentence or two for when and why a developer might pick each of these? I can guess, but I don't want to guess with defi.

**RoundDown** - Conservative for user payouts:

```cadence
// When calculating how much to pay out to users
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just leave this comment here but also add it to the sentence above. Adding a suggestion


### When to Use Each Mode

**RoundDown** - Conservative for user payouts:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**RoundDown** - Conservative for user payouts:
**RoundDown** - Select for user payouts to ensure the amount the protocol pays is never greater than what is owed:

**RoundEven** - Reduces cumulative rounding bias:

```cadence
// For repeated operations where bias matters
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When does bias matter? Can you link to an internal or external resource?

// result = 1500.0
```

**Important:** The multiplication uses `UInt256` internally to prevent overflow:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be an info admonition.

}
```

### Flexible Rounding Strategies
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the duplicate section on rounding?

let display = DeFiActionsMathUtils.toUFix64Round(calculatedValue)
```

### Gas Efficiency
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like a random ai addition

let afterFee: UFix64 = amount - fee
let output: UFix64 = afterFee * price
```

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we show a consequence here? What's below is much more complicated, we should demonstarte why it's worth it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One line though, not a complex example.
// XX.XX fee lost to the protocol @ amount of 1MM


## More Resources

- [View the DeFiActionsMathUtils source code](https://github.com/onflow/FlowActions/blob/main/cadence/contracts/utils/DeFiActionsMathUtils.cdc)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use reference-style links


## Conclusion

`DeFiActionsMathUtils` provides the mathematical foundation for building accurate and secure DeFi applications on Flow. By using 24-decimal fixed-point arithmetic with `UInt128`, you can perform complex financial calculations without the precision loss that would occur with native `UFix64` operations alone. No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restate advantages over other platforms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants