Skip to content

Commit

Permalink
add collection & vault configuration scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
sisyphusSmiling committed Jun 5, 2024
1 parent e41d781 commit fac0e0f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
30 changes: 30 additions & 0 deletions cadence/scripts/nft/has_collection_configured.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import "NonFungibleToken"
import "MetadataViews"
import "ViewResolver"

import "FlowEVMBridgeUtils"

/// Returns true if the recipient has Collection configured for the provided NFT contract
///
/// @param nftIdentifier The type identifier of the NFT Collection to check for
/// @param recipient The address of the recipient
///
/// @returns true if the recipient has Collection configured for the provided NFT contract, false if not. Reverts if the
/// provided contract cannot be accessed or does not have default Collection storage information.
///
access(all)
fun main(nftIdentifier: String, recipient: Address): Bool {
let nftType = CompositeType(nftIdentifier) ?? panic("Invalid nft identifier: ".concat(nftIdentifier))
let contractAddress = FlowEVMBridgeUtils.getContractAddress(fromType: nftType)
?? panic("Could not find contract address for nft: ".concat(nftIdentifier))
let contractName = FlowEVMBridgeUtils.getContractName(fromType: nftType)
?? panic("Could not find contract name for nft: ".concat(nftIdentifier))
let nftContract = getAccount(contractAddress).contracts.borrow<&{NonFungibleToken}>(name: contractName)
?? panic("No such contract found")
let collectionData = nftContract.resolveContractView(
resourceType: nftType,
viewType: Type<MetadataViews.NFTCollectionData>()
) as! MetadataViews.NFTCollectionData?
?? panic("FungibleToken does not provide default Collection data")
return getAccount(recipient).capabilities.exists(collectionData.publicPath)
}
30 changes: 30 additions & 0 deletions cadence/scripts/tokens/has_vault_configured.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import "FungibleToken"
import "FungibleTokenMetadataViews"
import "ViewResolver"

import "FlowEVMBridgeUtils"

/// Returns true if the recipient has Vault configured for the provided FungibleToken contract
///
/// @param vaultIdentifier The type identifier of the Vault to check for
/// @param recipient The address of the recipient
///
/// @returns true if the recipient has Vault configured for the provided FungibleToken contract, false if not. Reverts
/// if the provided contract cannot be accessed or does not have default Vault storage information.
///
access(all)
fun main(vaultIdentifier: String, recipient: Address): Bool {
let vaultType = CompositeType(vaultIdentifier) ?? panic("Invalid vault identifier: ".concat(vaultIdentifier))
let contractAddress = FlowEVMBridgeUtils.getContractAddress(fromType: vaultType)
?? panic("Could not find contract address for vault: ".concat(vaultIdentifier))
let contractName = FlowEVMBridgeUtils.getContractName(fromType: vaultType)
?? panic("Could not find contract name for vault: ".concat(vaultIdentifier))
let tokenContract = getAccount(contractAddress).contracts.borrow<&{FungibleToken}>(name: contractName)
?? panic("No such contract found")
let vaultData = tokenContract.resolveContractView(
resourceType: vaultType,
viewType: Type<FungibleTokenMetadataViews.FTVaultData>()
) as! FungibleTokenMetadataViews.FTVaultData?
?? panic("FungibleToken does not provide default Vault data")
return getAccount(recipient).capabilities.exists(vaultData.receiverPath)
}

0 comments on commit fac0e0f

Please sign in to comment.