Skip to content

Commit

Permalink
fix: adjust rounding error
Browse files Browse the repository at this point in the history
  • Loading branch information
Majorfi committed May 24, 2024
1 parent e6bc8ae commit 8f3cad4
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions apps/vaults/contexts/useActionFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -342,19 +342,21 @@ export function ActionFlowContextApp(props: {children: ReactNode; currentVault:
chainID: props.currentVault.chainID
});

const balanceWithRounding = toBigInt(vaultBalance.raw) - 10n;
const balance = toBigInt(vaultBalance.raw);
const maxRedeemWithRoundingSafety = toBigInt(limits?.maxRedeem) + 10n;

if (props.currentVault.version.startsWith('3')) {
const safeLimit = (toBigInt(limits?.maxRedeem) * 99n) / 100n;
return {
limit: toNormalizedBN(toBigInt(limits?.maxRedeem), props.currentVault.token.decimals),
safeLimit:
balanceWithRounding > toBigInt(limits?.maxRedeem)
balance > maxRedeemWithRoundingSafety
? toNormalizedBN(safeLimit, props.currentVault.token.decimals)
: toNormalizedBN(toBigInt(limits?.maxRedeem), props.currentVault.token.decimals),
isLimited: balanceWithRounding > toBigInt(limits?.maxRedeem)
isLimited: balance > maxRedeemWithRoundingSafety
};
}
if (toBigInt(limits?.maxRedeem) < balanceWithRounding) {
if (toBigInt(limits?.maxRedeem) < balance) {
return {
limit: toNormalizedBN(toBigInt(limits?.maxRedeem), props.currentVault.token.decimals),
safeLimit: toNormalizedBN(toBigInt(limits?.maxRedeem), props.currentVault.token.decimals),
Expand Down

0 comments on commit 8f3cad4

Please sign in to comment.