Skip to content

Commit

Permalink
Better naming for BalanceInAttFlowValidForFlowVault and fix logical c…
Browse files Browse the repository at this point in the history
…ondition
  • Loading branch information
m-Peter committed Jan 14, 2025
1 parent c644e3a commit f0e23ff
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion fvm/evm/emulator/emulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func (proc *procedure) withdrawFrom(
), nil
}

if types.BalanceInAttFlowValidForFlowVault(call.Value) {
if !types.AttoFlowBalanceValidForFlowVault(call.Value) {
return types.NewInvalidResult(
call.Transaction(),
types.ErrWithdrawBalanceRounding,
Expand Down
2 changes: 1 addition & 1 deletion fvm/evm/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ func newInternalEVMTypeWithdrawFunction(
panic(types.ErrInvalidBalance)
}

if types.BalanceInAttFlowValidForFlowVault(amountValue.BigInt) {
if !types.AttoFlowBalanceValidForFlowVault(amountValue.BigInt) {
panic(types.ErrWithdrawBalanceRounding)
}

Expand Down
6 changes: 3 additions & 3 deletions fvm/evm/types/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ func BalanceConversionToUFix64ProneToRoundingError(bal Balance) bool {
return new(big.Int).Mod(bal, UFixToAttoConversionMultiplier).BitLen() != 0
}

// BalanceInAttFlowValidForFlowVault returns true if the given balance,
// AttoFlowBalanceValidForFlowVault returns true if the given balance,
// represented as atto Flow, can be stored in a Flow Vault.
//
// Warning! The smallest unit of Flow token that a Flow Vault (Cadence)
// can store, is 1e10^-8 .
// That means the minimum balance, in atto Flow, that can be stored in a Flow Vault,
// is 1e10^10 .
func BalanceInAttFlowValidForFlowVault(bal *big.Int) bool {
return bal.Cmp(UFixToAttoConversionMultiplier) < 0
func AttoFlowBalanceValidForFlowVault(bal *big.Int) bool {
return bal.Cmp(UFixToAttoConversionMultiplier) >= 0
}

// Subtract balance 2 from balance 1 and returns the result as a new balance
Expand Down

0 comments on commit f0e23ff

Please sign in to comment.