Smart Contract

StarlyCollectorScore

A.5b82f21c0edf76e3.StarlyCollectorScore

Deployed

14h ago
Feb 28, 2026, 02:30:51 AM UTC

Dependents

0 imports
1access(all) contract StarlyCollectorScore {
2
3    access(all) struct Config {
4        access(all)
5        let editions: [[UInt32; 2]]
6        access(all)
7        let rest: UInt32
8        access(all)
9        let last: UInt32
10
11        init(
12            editions: [[UInt32; 2]],
13            rest: UInt32,
14            last: UInt32
15        ) {
16            self.editions = editions
17            self.rest = rest
18            self.last = last
19        }
20    }
21
22    access(contract) let configs: {String: {String: Config}}
23
24    access(all) let AdminStoragePath: StoragePath
25    access(all) let EditorStoragePath: StoragePath
26    access(all) let EditorProxyStoragePath: StoragePath
27    access(all) let EditorProxyPublicPath: PublicPath
28
29    access(all) fun getCollectorScore(
30        collectionID: String,
31        rarity: String,
32        edition: UInt32,
33        editions: UInt32,
34        priceCoefficient: UFix64
35    ): UFix64? {
36        let collectionConfig = self.configs[collectionID] ?? self.configs["default"] ?? panic("No score config found")
37        let rarityConfig = collectionConfig[rarity] ?? panic("No rarity config")
38
39        var editionScore: UInt32 = 0
40        if edition == editions && edition != 1 {
41            editionScore = rarityConfig.last
42        } else {
43            for e in rarityConfig.editions {
44                if edition <= e[0] {
45                    editionScore = e[1]
46                    break
47                }
48            }
49        }
50        if editionScore == 0 {
51            editionScore = rarityConfig.rest
52        }
53
54        return UFix64(editionScore) * priceCoefficient
55    }
56
57    access(all) resource interface IEditor {
58        access(all)
59        fun addCollectionConfig(collectionID: String, config: {String: Config})
60    }
61
62    access(all) resource Editor: IEditor {
63        access(all)
64        fun addCollectionConfig(collectionID: String, config: {String: Config}) {
65            StarlyCollectorScore.configs[collectionID] = config
66        }
67    }
68
69    access(all) resource interface EditorProxyPublic {
70        access(all)
71        fun setEditorCapability(cap: Capability<&Editor>)
72    }
73
74    access(all) resource EditorProxy: IEditor, EditorProxyPublic {
75        access(self) var editorCapability: Capability<&Editor>?
76
77        access(all) fun setEditorCapability(cap: Capability<&Editor>) {
78            self.editorCapability = cap
79        }
80
81        access(all) fun addCollectionConfig(collectionID: String, config: {String: Config}) {
82            self.editorCapability!.borrow()!
83            .addCollectionConfig(collectionID: collectionID, config: config)
84        }
85
86        init() {
87            self.editorCapability = nil
88        }
89    }
90
91    access(all) fun createEditorProxy(): @EditorProxy {
92        return <- create EditorProxy()
93    }
94
95    access(all) resource Admin {
96        access(all)
97        fun createNewEditor(): @Editor {
98            return <- create Editor()
99        }
100    }
101
102    init () {
103        self.AdminStoragePath = /storage/starlyCollectorScoreAdmin
104        self.EditorStoragePath = /storage/starlyCollectorScoreEditor
105        self.EditorProxyPublicPath = /public/starlyCollectorScoreEditorProxy
106        self.EditorProxyStoragePath = /storage/starlyCollectorScoreEditorProxy
107
108        let admin <- create Admin()
109        let editor <- admin.createNewEditor()
110        self.account.storage.save(<-admin, to: self.AdminStoragePath)
111        self.account.storage.save(<-editor, to: self.EditorStoragePath)
112
113        self.configs = {}
114    }
115}
116