Smart Contract

DeFiActionsUtils

A.6d888f175c158410.DeFiActionsUtils

Valid From

131,176,092

Deployed

1w ago
Feb 19, 2026, 09:00:31 AM UTC

Dependents

4 imports
1import FungibleToken from 0xf233dcee88fe0abe
2
3/// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
4/// THIS CONTRACT IS IN BETA AND IS NOT FINALIZED - INTERFACES MAY CHANGE AND/OR PENDING CHANGES MAY REQUIRE REDEPLOYMENT
5/// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6///
7/// DeFiActionsUtils
8///
9/// Utility methods commonly used across DeFiActions related contracts
10///
11access(all) contract DeFiActionsUtils {
12
13    /// Checks that the contract defining vaultType conforms to the FungibleToken contract interface. This is required
14    /// to source empty Vaults in the event inner Capabilities become invalid
15    ///
16    /// @param vaultType: The Type of the Vault in question
17    ///
18    /// @return true if the Type a Vault and is defined by a FungibleToken contract, false otherwise
19    ///
20    access(all) view fun definingContractIsFungibleToken(_ vaultType: Type): Bool {
21        if !vaultType.isSubtype(of: Type<@{FungibleToken.Vault}>()) {
22            return false
23        }
24        return getAccount(vaultType.address!).contracts.borrow<&{FungibleToken}>(name: vaultType.contractName!) != nil
25    }
26
27    /// Returns an empty Vault of the given Type. Reverts if the provided Type is not defined by a FungibleToken
28    /// or if the returned Vault is not of the requested Type. Callers can use .definingContractIsFungibleToken()
29    /// to check the type before calling if they would like to prevent reverting.
30    ///
31    /// @param vaultType: The Type of the Vault to return as an empty Vault
32    ///
33    /// @return an empty Vault of the requested Type
34    ///
35    access(all) fun getEmptyVault(_ vaultType: Type): @{FungibleToken.Vault} {
36        pre {
37            self.definingContractIsFungibleToken(vaultType):
38            "Invalid vault Type \(vaultType.identifier) requested - cannot create an empty Vault of an invalid type"
39        }
40        post {
41            result.getType() == vaultType:
42            "Invalid Vault returned - expected \(vaultType.identifier) but returned \(result.getType().identifier)"
43        }
44        return <- getAccount(vaultType.address!)
45            .contracts
46            .borrow<&{FungibleToken}>(name: vaultType.contractName!)!
47            .createEmptyVault(vaultType: vaultType)
48    }
49}
50