DeploySEALED
!$▫╱?╱▪□◆?╲◇◇$▪@▪○◇╱#?●□╲**●╲◇▓◇#◇╲▫$╱╳●╳◇○^○■^╳~╳●&○!╳▓▪^$○○●#█
Transaction ID
Execution Fee
0.00000259 FLOWTransaction Summary
DeployContract deployment
Contract deployment
Script Arguments
0nameString
FlowRewardsValets
1codeString
import NonFungibleToken from 0x1d7e57aa55817448
import FlowToken from 0x1654653399040a61
import FlowRewards from 0xa45ead1cf1ca9eda
/// This contract defines vehicles for reward delivery used in the CrescedoRewards contract so NFT owners can claim
/// various rewards. Claiming logic is defined in the Valet resource and the ValetFactory resource is used to create
/// these valet implementations.
///
access(all) contract FlowRewardsValets {
/// The cannonical storage path for the ValetFactory
access(all) let ValetFactoryStoragePath: StoragePath
/// A resource that enables the claim of rewards distributions against a FlowRewards NFT
///
access(all) resource DistributionValet : FlowRewards.Valet {
/// Returns the types of resources that can be claimed by this valet
///
/// @return The claimable types
///
access(all) fun getClaimableTypes(): [Type] {
return [ Type<@FlowToken.Vault>() ]
}
/// Returns the eligible claims for a given NFT indexed on the claimable asset type
/// NOTE: Although the value of the inner mapping is a UFix64, the amount may be used to represent a quantity
/// of the claimable asset - e.g. {ExampleNFT: 1.0} may indicate 1 ExampleNFT can be claimed
///
/// @param forNFT: The ID of the NFT to check for eligible claims
///
/// @return A mapping of claimable asset types to the amount that can be claimed
///
access(all) fun getEligibleClaims(forNFT: UInt64): {Type: UFix64} {
// Retrieve the summary for the NFT
if let summary = FlowRewards._borrowSummary(forNFT: forNFT) {
// Calculate the total claimable amount
let lockedClaim = FlowRewards._getAllowableDistribution(summary, locked: true, atTime: nil) ?? 0.0
let rewardsClaim = FlowRewards._getAllowableDistribution(summary, locked: false, atTime: nil) ?? 0.0
return {
Type<@FlowToken.Vault>(): lockedClaim + rewardsClaim
}
}
return {}
}
/// Claims a reward distribution against a given NFT
///
/// @param forNFT: The NFT to claim rewards from
/// @param claimType: The type of asset to claim
///
/// @return The claimed resource or nil if the claim is not supported
///
access(all) fun claim(forNFT: &FlowRewards.NFT, claimType: Type): @AnyResource? {
// Only FlowToken is supported via this Valet
if claimType != Type<@FlowToken.Vault>() {
return nil
}
return <- FlowRewards._claimDistribution(forNFT: forNFT)
}
}
/// Creates Valet implementations defined in this contract
///
access(all) resource ValetFactory {
/// Returns a valet implementation for the given type or nil if the type is not supported
///
access(all) fun createValet(_ type: Type): @{FlowRewards.Valet}? {
switch type {
case Type<@FlowRewardsValets.DistributionValet>():
return <-create DistributionValet()
default:
return nil
}
}
}
init() {
self.ValetFactoryStoragePath = /storage/flowRewardsValetFactory
self.account.save(<-create ValetFactory(), to: self.ValetFactoryStoragePath)
}
}
Cadence Script
1transaction(name: String, code: String ) {
2 prepare(signer: AuthAccount) {
3 signer.contracts.add(name: name, code: code.utf8 )
4 }
5 }