Smart Contract

FlowRewardsValets

A.a45ead1cf1ca9eda.FlowRewardsValets

Valid From

85,389,723

Deployed

2d ago
Feb 25, 2026, 07:03:31 PM UTC

Dependents

6 imports
1import NonFungibleToken from 0x1d7e57aa55817448
2import FlowToken from 0x1654653399040a61
3
4import FlowRewards from 0xa45ead1cf1ca9eda
5
6/// This contract defines vehicles for reward delivery used in the CrescedoRewards contract so NFT owners can claim
7/// various rewards. Claiming logic is defined in the Valet resource and the ValetFactory resource is used to create
8/// these valet implementations.
9///
10access(all) contract FlowRewardsValets {
11
12    /// The cannonical storage path for the ValetFactory
13    access(all) let ValetFactoryStoragePath: StoragePath
14
15    /// A resource that enables the claim of rewards distributions against a FlowRewards NFT
16    ///
17    access(all) resource DistributionValet : FlowRewards.Valet {
18        /// Returns the types of resources that can be claimed by this valet
19        ///
20        /// @return The claimable types
21        ///
22        access(all) view fun getClaimableTypes(): [Type] {
23            return [ Type<@FlowToken.Vault>() ]
24        }
25
26        /// Returns the eligible claims for a given NFT indexed on the claimable asset type
27        /// NOTE: Although the value of the inner mapping is a UFix64, the amount may be used to represent a quantity
28        ///     of the claimable asset - e.g. {ExampleNFT: 1.0} may indicate 1 ExampleNFT can be claimed
29        ///
30        /// @param forNFT: The ID of the NFT to check for eligible claims
31        ///
32        /// @return A mapping of claimable asset types to the amount that can be claimed
33        ///
34        access(all) fun getEligibleClaims(forNFT: UInt64): {Type: UFix64} {
35            // Retrieve the summary for the NFT
36            if let summary = FlowRewards._borrowSummary(forNFT: forNFT) {
37                // Calculate the total claimable amount
38                let lockedClaim = FlowRewards._getAllowableDistribution(summary, locked: true, atTime: nil) ?? 0.0
39                let rewardsClaim = FlowRewards._getAllowableDistribution(summary, locked: false, atTime: nil) ?? 0.0
40                return {
41                    Type<@FlowToken.Vault>(): lockedClaim + rewardsClaim
42                }
43            }
44            return {}
45        }
46
47        /// Claims a reward distribution against a given NFT
48        ///
49        /// @param forNFT: The NFT to claim rewards from
50        /// @param claimType: The type of asset to claim
51        ///
52        /// @return The claimed resource or nil if the claim is not supported
53        ///
54        access(FlowRewards.Claim) fun claim(forNFT: &FlowRewards.NFT, claimType: Type): @AnyResource? {
55            // Only FlowToken is supported via this Valet
56            if claimType != Type<@FlowToken.Vault>() {
57                return nil
58            }
59            return <- FlowRewards._claimDistribution(forNFT: forNFT)
60        }
61    }
62
63    /// Creates Valet implementations defined in this contract
64    ///
65    access(all) resource ValetFactory {
66        /// Returns a valet implementation for the given type or nil if the type is not supported
67        ///
68        access(all) fun createValet(_ type: Type): @{FlowRewards.Valet}? {
69            switch type {
70                case Type<@FlowRewardsValets.DistributionValet>():
71                    return <-create DistributionValet()
72                default:
73                    return nil
74            }
75        }
76    }
77
78    init() {
79        self.ValetFactoryStoragePath = /storage/flowRewardsValetFactory
80
81        self.account.storage.save(<-create ValetFactory(), to: self.ValetFactoryStoragePath)
82    }
83}