Skip to content

Commit

Permalink
update fee calculation usage on new interface
Browse files Browse the repository at this point in the history
  • Loading branch information
sisyphusSmiling committed Apr 15, 2024
1 parent 52b84d4 commit 0d29f8b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
14 changes: 7 additions & 7 deletions cadence/contracts/bridge/FlowEVMBridge.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ contract FlowEVMBridge : IFlowEVMNFTBridge, IFlowEVMTokenBridge {
// Lock the NFT & calculate the storage used by the NFT
let storageUsed = FlowEVMBridgeNFTEscrow.lockNFT(<-token)
// Calculate the bridge fee on current rates
let feeAmount = FlowEVMBridgeUtils.calculateBridgeFee(used: storageUsed, includeBase: true)
let feeAmount = FlowEVMBridgeUtils.calculateBridgeFee(bytes: storageUsed)
assert(
feeProvider.isAvailableToWithdraw(amount: feeAmount),
message: "Fee provider does not have balance to cover the bridge fee of ".concat(feeAmount.toString())
Expand Down Expand Up @@ -308,13 +308,13 @@ contract FlowEVMBridge : IFlowEVMNFTBridge, IFlowEVMTokenBridge {
protectedTransferCall: fun (): EVM.Result
): @{NonFungibleToken.NFT} {
pre {
feeProvider.isAvailableToWithdraw(amount: FlowEVMBridgeUtils.calculateBridgeFee(used: 0, includeBase: true)):
feeProvider.isAvailableToWithdraw(amount: FlowEVMBridgeUtils.calculateBridgeFee(bytes: 0)):
"Insufficient fee paid"
!type.isSubtype(of: Type<@{FungibleToken.Vault}>()): "Mixed asset types are not yet supported"
self.typeRequiresOnboarding(type) == false: "NFT must first be onboarded"
}
// Withdraw from feeProvider and deposit to self
let feeAmount = FlowEVMBridgeUtils.calculateBridgeFee(used: 0, includeBase: true)
let feeAmount = FlowEVMBridgeUtils.calculateBridgeFee(bytes: 0)
let feeVault <-feeProvider.withdraw(amount: feeAmount) as! @FlowToken.Vault
FlowEVMBridgeUtils.deposit(<-feeVault)

Expand Down Expand Up @@ -401,10 +401,10 @@ contract FlowEVMBridge : IFlowEVMNFTBridge, IFlowEVMTokenBridge {
// Lock the FT balance & calculate the extra used by the FT if any
let storageUsed = FlowEVMBridgeTokenEscrow.lockTokens(<-vault)
// Calculate the bridge fee on current rates
feeAmount = FlowEVMBridgeUtils.calculateBridgeFee(used: storageUsed, includeBase: true)
feeAmount = FlowEVMBridgeUtils.calculateBridgeFee(bytes: storageUsed)
} else {
Burner.burn(<-vault)
feeAmount = FlowEVMBridgeUtils.calculateBridgeFee(used: 0, includeBase: true)
feeAmount = FlowEVMBridgeUtils.calculateBridgeFee(bytes: 0)
}

// Withdraw from feeProvider and deposit to self
Expand Down Expand Up @@ -469,14 +469,14 @@ contract FlowEVMBridge : IFlowEVMNFTBridge, IFlowEVMTokenBridge {
protectedTransferCall: fun (): EVM.Result
): @{FungibleToken.Vault} {
pre {
feeProvider.isAvailableToWithdraw(amount: FlowEVMBridgeUtils.calculateBridgeFee(used: 0, includeBase: true)):
feeProvider.isAvailableToWithdraw(amount: FlowEVMBridgeUtils.calculateBridgeFee(bytes: 0)):
"Insufficient fee paid"
!type.isSubtype(of: Type<@{NonFungibleToken.Collection}>()): "Mixed asset types are not yet supported"
!type.isInstance(Type<@FlowToken.Vault>()): "Must use the CadenceOwnedAccount interface to bridge $FLOW from EVM"
self.typeRequiresOnboarding(type) == false: "NFT must first be onboarded"
}
// Withdraw from feeProvider and deposit to self
let feeAmount = FlowEVMBridgeUtils.calculateBridgeFee(used: 0, includeBase: true)
let feeAmount = FlowEVMBridgeUtils.calculateBridgeFee(bytes: 0)
let feeVault <-feeProvider.withdraw(amount: feeAmount) as! @FlowToken.Vault
FlowEVMBridgeUtils.deposit(<-feeVault)

Expand Down
2 changes: 1 addition & 1 deletion cadence/transactions/bridge/nft/bridge_nft_from_evm.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ transaction(nftContractAddress: Address, nftContractName: String, id: UInt256) {
/* --- Configure a ScopedFTProvider --- */
//
// Calculate the bridge fee - bridging from EVM consumes no storage, so flat fee
let approxFee = FlowEVMBridgeUtils.calculateBridgeFee(used: 0, includeBase: true)
let approxFee = FlowEVMBridgeUtils.calculateBridgeFee(bytes: 0)
// Issue and store bridge-dedicated Provider Capability in storage if necessary
if signer.storage.type(at: FlowEVMBridgeConfig.providerCapabilityStoragePath) == nil {
let providerCap = signer.capabilities.storage.issue<auth(FungibleToken.Withdraw) &{FungibleToken.Provider}>(
Expand Down
3 changes: 1 addition & 2 deletions cadence/transactions/bridge/nft/bridge_nft_to_evm.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ transaction(nftContractAddress: Address, nftContractName: String, id: UInt64) {
self.nft <- collection.withdraw(withdrawID: id)
let withdrawnStorageUsage = signer.storage.used
let approxFee = FlowEVMBridgeUtils.calculateBridgeFee(
used: currentStorageUsage - withdrawnStorageUsage,
includeBase: true
bytes: currentStorageUsage - withdrawnStorageUsage
) * 1.10

/* --- Configure a ScopedFTProvider --- */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ transaction(tokenContractAddress: Address, tokenContractName: String, amount: UI
/* --- Configure a ScopedFTProvider --- */
//
// Calculate the bridge fee - bridging from EVM consumes no storage, so flat fee
let approxFee = FlowEVMBridgeUtils.calculateBridgeFee(used: 0, includeBase: true)
let approxFee = FlowEVMBridgeUtils.calculateBridgeFee(bytes: 0)
// Issue and store bridge-dedicated Provider Capability in storage if necessary
if signer.storage.type(at: FlowEVMBridgeConfig.providerCapabilityStoragePath) == nil {
let providerCap = signer.capabilities.storage.issue<auth(FungibleToken.Withdraw) &{FungibleToken.Provider}>(
Expand Down
3 changes: 1 addition & 2 deletions cadence/transactions/bridge/tokens/bridge_tokens_to_evm.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ transaction(tokenContractAddress: Address, tokenContractName: String, amount: UF
let withdrawnStorageUsage = signer.storage.used
// Approximate the bridge fee based on the difference in storage usage with some buffer
let approxFee = FlowEVMBridgeUtils.calculateBridgeFee(
used: currentStorageUsage - withdrawnStorageUsage,
includeBase: true
bytes: currentStorageUsage - withdrawnStorageUsage
) * 1.10

/* --- Configure a ScopedFTProvider --- */
Expand Down

0 comments on commit 0d29f8b

Please sign in to comment.