From 52b84d42d994e37e9e34c487df2eaed73c763a3d Mon Sep 17 00:00:00 2001 From: Giovanni Sanchez <108043524+sisyphusSmiling@users.noreply.github.com> Date: Fri, 12 Apr 2024 18:57:20 -0500 Subject: [PATCH] replace FlowEVMBridgeConfig.storageRate with FlowStorageFees rate calculation --- .../contracts/bridge/FlowEVMBridgeConfig.cdc | 20 ------------------- .../contracts/bridge/FlowEVMBridgeUtils.cdc | 16 +++++++-------- cadence/scripts/config/get_storage_rate.cdc | 5 ----- .../bridge/admin/update_storage_rate.cdc | 15 -------------- 4 files changed, 7 insertions(+), 49 deletions(-) delete mode 100644 cadence/scripts/config/get_storage_rate.cdc delete mode 100644 cadence/transactions/bridge/admin/update_storage_rate.cdc diff --git a/cadence/contracts/bridge/FlowEVMBridgeConfig.cdc b/cadence/contracts/bridge/FlowEVMBridgeConfig.cdc index 97363ea6..406dcc36 100644 --- a/cadence/contracts/bridge/FlowEVMBridgeConfig.cdc +++ b/cadence/contracts/bridge/FlowEVMBridgeConfig.cdc @@ -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 @@ -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 @@ -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( diff --git a/cadence/contracts/bridge/FlowEVMBridgeUtils.cdc b/cadence/contracts/bridge/FlowEVMBridgeUtils.cdc index 25ea3726..bc0e158c 100644 --- a/cadence/contracts/bridge/FlowEVMBridgeUtils.cdc +++ b/cadence/contracts/bridge/FlowEVMBridgeUtils.cdc @@ -3,6 +3,7 @@ import "FungibleToken" import "MetadataViews" import "ViewResolver" import "FlowToken" +import "FlowStorageFees" import "EVM" @@ -74,9 +75,8 @@ 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 @@ -84,12 +84,10 @@ contract FlowEVMBridgeUtils { /// @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. diff --git a/cadence/scripts/config/get_storage_rate.cdc b/cadence/scripts/config/get_storage_rate.cdc deleted file mode 100644 index d43691ae..00000000 --- a/cadence/scripts/config/get_storage_rate.cdc +++ /dev/null @@ -1,5 +0,0 @@ -import "FlowEVMBridgeConfig" - -access(all) fun main(): UFix64 { - return FlowEVMBridgeConfig.storageRate -} diff --git a/cadence/transactions/bridge/admin/update_storage_rate.cdc b/cadence/transactions/bridge/admin/update_storage_rate.cdc deleted file mode 100644 index 79fb2f7a..00000000 --- a/cadence/transactions/bridge/admin/update_storage_rate.cdc +++ /dev/null @@ -1,15 +0,0 @@ -import "FlowEVMBridgeConfig" - -/// Sets the storage rate charged per base storage unit paid for escrowed asset storage. -/// -/// @param newFee: The cost per base unit of storage -/// -/// @emits FlowEVMBridgeConfig.StorageRateUpdated(old: FlowEVMBridgeConfig.baseFee, new: newFee) -/// -transaction(newFee: UFix64) { - prepare(signer: auth(BorrowValue) &Account) { - signer.storage.borrow<&FlowEVMBridgeConfig.Admin>(from: FlowEVMBridgeConfig.adminStoragePath) - ?.updateStorageRate(newFee) - ?? panic("Could not borrow FlowEVMBridgeConfig Admin reference") - } -}