From fac0e0f39a7d26f8ade624797e2f1826120c7b1f Mon Sep 17 00:00:00 2001 From: Giovanni Sanchez <108043524+sisyphusSmiling@users.noreply.github.com> Date: Wed, 5 Jun 2024 17:05:58 -0600 Subject: [PATCH] add collection & vault configuration scripts --- .../scripts/nft/has_collection_configured.cdc | 30 +++++++++++++++++++ .../scripts/tokens/has_vault_configured.cdc | 30 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 cadence/scripts/nft/has_collection_configured.cdc create mode 100644 cadence/scripts/tokens/has_vault_configured.cdc diff --git a/cadence/scripts/nft/has_collection_configured.cdc b/cadence/scripts/nft/has_collection_configured.cdc new file mode 100644 index 00000000..f22685cc --- /dev/null +++ b/cadence/scripts/nft/has_collection_configured.cdc @@ -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() + ) as! MetadataViews.NFTCollectionData? + ?? panic("FungibleToken does not provide default Collection data") + return getAccount(recipient).capabilities.exists(collectionData.publicPath) +} diff --git a/cadence/scripts/tokens/has_vault_configured.cdc b/cadence/scripts/tokens/has_vault_configured.cdc new file mode 100644 index 00000000..07643442 --- /dev/null +++ b/cadence/scripts/tokens/has_vault_configured.cdc @@ -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() + ) as! FungibleTokenMetadataViews.FTVaultData? + ?? panic("FungibleToken does not provide default Vault data") + return getAccount(recipient).capabilities.exists(vaultData.receiverPath) +}