DeploySEALED
◇^◆%◇▓#◇!█◇□░*▒▒@╱%$~▒▪%%**●╲▪■~█□◇╲◆█◆▓░□^%%#╲?█○~░^○▓~░●█%▫○&!
Transaction ID
Execution Fee
0.00000209 FLOWTransaction Summary
DeployContract deployment
Contract deployment
Script Arguments
0nameString
FlowRewardsMetadataViews
1codeString
import FlowRewardsRegistry from 0xa45ead1cf1ca9eda
/// This contract defines the views available for metadata retrieval from FlowRewards NFTs
///
access(all) contract FlowRewardsMetadataViews {
/// A rich data structure capturing the overview of a given NFT
///
access(all) struct LockOverview {
/// The id of the corresponding NFT
access(all) let id: UInt64
/// The sequence number of the NFT AKA the order this NFT was minted in
access(all) let sequence: UInt64
/// The tier of the associated NFT
access(all) let tier: UInt8
/// The tier name of the associated NFT
access(all) let tierName: String
/// The timestamp at which the NFT was minted
access(all) let mintedTimestamp: UFix64
/// All lockup entries executed by associated NFT
access(all) let lockups: [{FlowRewardsRegistry.Lockup}]
/// The total value locked under the NFT
access(all) let totalLocked: UFix64
/// The total boost amount in rewards under the NFT
access(all) let totalRewards: UFix64
/// The total value that can be distributed as locked funds
access(all) let allowableLockedDistribution: UFix64
/// The total value that has been claimed as locked funds
access(all) let lockedClaimed: UFix64
/// The total value that can be distributed as rewards
access(all) let allowableRewardDistribution: UFix64
/// The total value that has been claimed as rewards
access(all) let rewardsClaimed: UFix64
/// The total remaining FLOW that can be distributed
access(all) let totalRemainingFlow: UFix64
init(
id: UInt64,
sequence: UInt64,
tier: UInt8,
tierName: String,
lockups: [{FlowRewardsRegistry.Lockup}],
totalLocked: UFix64,
totalRewards: UFix64,
allowableLockedDistribution: UFix64,
lockedClaimed: UFix64,
allowableRewardDistribution: UFix64,
rewardsClaimed: UFix64
) {
pre {
lockups.length > 0: "Rewards NFTs cannot exist without at least 1 lockup"
}
self.id = id
self.sequence = sequence
self.tier = tier
self.tierName = tierName
self.mintedTimestamp = lockups[0].timestamp
self.lockups = lockups
self.totalLocked = totalLocked
self.totalRewards = totalRewards
self.allowableLockedDistribution = allowableLockedDistribution
self.lockedClaimed = lockedClaimed
self.allowableRewardDistribution = allowableRewardDistribution
self.rewardsClaimed = rewardsClaimed
self.totalRemainingFlow = totalLocked + totalRewards - lockedClaimed - rewardsClaimed
}
}
/// A data structure intended to render metadata for a given NFT into an SVG string
///
access(all) struct interface Renderer {
access(all) fun render(
metadata: {String: AnyStruct}
): String
}
/// A renderer that renders the metadata of a given NFT into an SVG string, depicting a display related to locked
/// and rewards values
///
access(all) struct LockSVGRenderer : Renderer {
/// The svg template to be rendered given NFT metadata
access(all) let template: [String]
init(template: [String]) {
pre {
template.length == 12:
"Expected 12 elements in the template - template length=".concat(template.length.toString())
}
self.template = template
}
/// Renders the SVG template with the given NFT metadata
///
/// @param metadata: The metadata of the NFT to be rendered with values expected for:
/// - id: UInt64
/// - tier: String
/// - totalLocked: UFix64
/// - totalRewards: UFix64
/// - lockedClaimed: UFix64
/// - rewardsClaimed: UFix64
///
/// @return: The SVG string rendered with the given metadata. If utilizing in an NFT view, this string should be
/// base64 encoded
///
access(all) fun render(
metadata: {String: AnyStruct}
): String {
// Access the metadata values
let id = metadata["id"] as! UInt64? ?? panic("Malformed metadata - missing id")
let tier = metadata["tierName"] as! String? ?? panic("Malformed metadata - missing tierName")
let totalLocked = metadata["totalLocked"] as! UFix64? ?? panic("Malformed metadata - missing totalLocked")
let totalRewards = metadata["totalRewards"] as! UFix64? ?? panic("Malformed metadata - missing totalRewards")
let lockedClaimed = metadata["lockedClaimed"] as! UFix64? ?? panic("Malformed metadata - missing lockedClaimed")
let rewardsClaimed = metadata["rewardsClaimed"] as! UFix64? ?? panic("Malformed metadata - missing rewardsClaimed")
// Convert to expected formats and render the SVG from the template
let lockedString = totalLocked.toString()
let rewardsString = (metadata["totalRewards"] as! UFix64?)!.toString()
let remainingString = (totalLocked + totalRewards - lockedClaimed - rewardsClaimed).toString()
let truncatedLockedString = lockedString.slice(from: 0, upTo: lockedString.length - 6)
let truncatedRewardsString = rewardsString.slice(from: 0, upTo: rewardsString.length - 6)
let truncatedRemainingString = remainingString.slice(from: 0, upTo: remainingString.length - 6)
return self.template[0].concat(truncatedRemainingString)
.concat(self.template[1]).concat(truncatedRewardsString)
.concat(self.template[2]).concat(truncatedLockedString)
.concat(self.template[3]).concat(id.toString())
.concat(self.template[4]).concat(tier)
.concat(self.template[5]).concat(lockedString)
.concat(self.template[6]).concat(rewardsString)
.concat(self.template[7]).concat(remainingString)
.concat(self.template[8]).concat(lockedString)
.concat(self.template[9]).concat(rewardsString)
.concat(self.template[10]).concat(remainingString)
.concat(self.template[11])
}
}
}
Cadence Script
1transaction(name: String, code: String ) {
2 prepare(signer: AuthAccount) {
3 signer.contracts.add(name: name, code: code.utf8 )
4 }
5 }