Skip to content

Commit

Permalink
replace FlowEVMBridgeConfig.storageRate with FlowStorageFees rate cal…
Browse files Browse the repository at this point in the history
…culation
  • Loading branch information
sisyphusSmiling committed Apr 15, 2024
1 parent e2d59f2 commit 52b84d4
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 49 deletions.
20 changes: 0 additions & 20 deletions cadence/contracts/bridge/FlowEVMBridgeConfig.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ contract FlowEVMBridgeConfig {
/// Flat rate fee for all bridge requests
access(all)
var baseFee: UFix64
/// Fee rate per storage unit consumed by bridged assets
access(all)
var storageRate: UFix64
/// Default ERC20.decimals() value
access(all)
let defaultDecimals: UInt8
Expand All @@ -42,10 +39,6 @@ contract FlowEVMBridgeConfig {
///
access(all)
event BridgeFeeUpdated(old: UFix64, new: UFix64, isOnboarding: Bool)
/// Emitted whenever baseFee or storageRate is updated
///
access(all)
event StorageRateUpdated(old: UFix64, new: UFix64)

/*************
Getters
Expand Down Expand Up @@ -101,24 +94,11 @@ contract FlowEVMBridgeConfig {
emit BridgeFeeUpdated(old: FlowEVMBridgeConfig.baseFee, new: new, isOnboarding: false)
FlowEVMBridgeConfig.baseFee = new
}

/// Updates the storage rate
///
/// @param new: UFix64 - new storage rate
///
/// @emits StorageRateUpdated with the old and new rates
///
access(all)
fun updateStorageRate(_ new: UFix64) {
emit StorageRateUpdated(old: FlowEVMBridgeConfig.baseFee, new: new)
FlowEVMBridgeConfig.baseFee = new
}
}

init() {
self.onboardFee = 0.0
self.baseFee = 0.0
self.storageRate = 0.0
self.defaultDecimals = 18
self.typeToEVMAddress = {
Type<@FlowToken.Vault>(): EVM.EVMAddress(
Expand Down
16 changes: 7 additions & 9 deletions cadence/contracts/bridge/FlowEVMBridgeUtils.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import "FungibleToken"
import "MetadataViews"
import "ViewResolver"
import "FlowToken"
import "FlowStorageFees"

import "EVM"

Expand Down Expand Up @@ -74,22 +75,19 @@ contract FlowEVMBridgeUtils {
])
}

/// Validates the Vault used to pay the bridging fee
/// NOTE: Currently fees are calculated at a flat base fee, but may be dynamically calculated based on storage
/// used by escrowed assets in the future
/// Calculates the fee bridge fee based on the given storage usage. If includeBase is true, the base fee is included
/// in the resulting calculation.
///
/// @param used: The amount of storage used by the asset
/// @param includeBase: Whether to include the base fee in the calculation
///
/// @return The calculated fee amount
///
access(all)
view fun calculateBridgeFee(used: UInt64, includeBase: Bool): UFix64 {
// TODO: Include storage-based fee calculation
// let x = FlowStorageFees.convertUInt64StorageBytesToUFix64Megabytes(used) * FlowEVMBridgeConfig.storageRate
let y = includeBase ? FlowEVMBridgeConfig.baseFee : 0.0
// return x + y
return y
view fun calculateBridgeFee(bytes used: UInt64): UFix64 {
let megabytesUsed = FlowStorageFees.convertUInt64StorageBytesToUFix64Megabytes(used)
let storageFee = FlowStorageFees.storageCapacityToFlow(megabytesUsed)
return storageFee + FlowEVMBridgeConfig.baseFee
}

/// Returns whether the given type is allowed to be bridged as defined by the BridgePermissions contract interface.
Expand Down
5 changes: 0 additions & 5 deletions cadence/scripts/config/get_storage_rate.cdc

This file was deleted.

15 changes: 0 additions & 15 deletions cadence/transactions/bridge/admin/update_storage_rate.cdc

This file was deleted.

0 comments on commit 52b84d4

Please sign in to comment.