Smart Contract
FindMarketCutStruct
A.097bafa4e0b48eef.FindMarketCutStruct
1import FungibleToken from 0xf233dcee88fe0abe
2import MetadataViews from 0x1d7e57aa55817448
3
4access(all) contract FindMarketCutStruct {
5
6 access(all) struct Cuts {
7 access(all) let cuts : [{Cut}]
8 access(contract) let extra: {String : AnyStruct}
9
10 init(cuts: [{Cut}]) {
11 self.cuts = cuts
12 self.extra = {}
13 }
14
15 access(all) fun getEventSafeCuts() : [EventSafeCut] {
16 let cuts : [EventSafeCut] = []
17 for c in self.cuts {
18 cuts.append(c.getEventSafeCut())
19 }
20 return cuts
21 }
22 }
23
24 access(all) struct EventSafeCut {
25 access(all) let name: String
26 access(all) let description: String
27 access(all) let cut: UFix64
28 access(all) let receiver: Address
29 access(all) let extra: {String : String}
30
31 init(name: String, description: String, cut: UFix64, receiver: Address, extra: {String : String}) {
32 self.name = name
33 self.description = description
34 self.cut = cut
35 self.receiver = receiver
36 self.extra = extra
37 }
38 }
39
40 access(all) struct interface Cut {
41 access(all) fun getName() : String
42 access(all) fun getReceiverCap() : Capability<&{FungibleToken.Receiver}>
43 access(all) fun getCut() : UFix64
44 access(all) fun getAddress() : Address
45 access(all) fun getDescription() : String
46 access(all) fun getPayableLogic() : (fun(UFix64) : UFix64?)
47 access(all) fun getExtra() : {String : String}
48
49 access(all) fun getRoyalty() : MetadataViews.Royalty {
50 let cap = self.getReceiverCap()
51 return MetadataViews.Royalty(receiver: cap, cut: self.getCut(), description: self.getName())
52 }
53
54 access(all) fun getAmountPayable(_ salePrice: UFix64) : UFix64? {
55 if let cut = self.getPayableLogic()(salePrice) {
56 return cut
57 }
58 return nil
59 }
60
61 access(all) fun getEventSafeCut() : EventSafeCut {
62 return EventSafeCut(
63 name: self.getName(),
64 description: self.getDescription(),
65 cut: self.getCut(),
66 receiver: self.getAddress(),
67 extra: self.getExtra()
68 )
69 }
70 }
71
72 access(all) struct GeneralCut : Cut {
73 // This is the description of the royalty struct
74 access(all) let name : String
75 access(all) let cap: Capability<&{FungibleToken.Receiver}>
76 access(all) let cut: UFix64
77 // This is the description to the cut that can be visible to give detail on detail page
78 access(all) let description: String
79 access(self) let extra : {String : AnyStruct}
80
81 init(name : String, cap: Capability<&{FungibleToken.Receiver}>, cut: UFix64, description: String) {
82 self.name = name
83 self.cap = cap
84 self.cut = cut
85 self.description = description
86 self.extra = {}
87 }
88
89 access(all) fun getReceiverCap() : Capability<&{FungibleToken.Receiver}> {
90 return self.cap
91 }
92 access(all) fun getName() : String {
93 return self.name
94 }
95 access(all) fun getCut() : UFix64 {
96 return self.cut
97 }
98 access(all) fun getAddress() : Address {
99 return self.cap.address
100 }
101 access(all) fun getDescription() : String {
102 return self.description
103 }
104 access(all) fun getExtra() : {String : String} {
105 return {}
106 }
107
108 access(all) fun getPayableLogic() : (fun(UFix64) : UFix64?) {
109 return fun(_ salePrice : UFix64) : UFix64? {
110 return salePrice * self.cut
111 }
112 }
113 }
114
115 access(all) struct ThresholdCut : Cut {
116 // This is the description of the royalty struct
117 access(all) let name : String
118 access(all) let address: Address
119 access(all) let cut: UFix64
120 // This is the description to the cut that can be visible to give detail on detail page
121 access(all) let description: String
122 access(all) let publicPath: String
123 access(all) let minimumPayment: UFix64
124 access(self) let extra : {String : AnyStruct}
125
126 init(name : String , address: Address , cut: UFix64 , description: String , publicPath: String, minimumPayment: UFix64) {
127 self.name = name
128 self.address = address
129 self.cut = cut
130 self.description = description
131 self.publicPath = publicPath
132 self.minimumPayment = minimumPayment
133 self.extra = {}
134 }
135
136 access(all) fun getReceiverCap() : Capability<&{FungibleToken.Receiver}> {
137 let pp = PublicPath(identifier: self.publicPath)!
138 return getAccount(self.address).capabilities.get<&{FungibleToken.Receiver}>(pp)!
139 }
140 access(all) fun getName() : String {
141 return self.name
142 }
143 access(all) fun getCut() : UFix64 {
144 return self.cut
145 }
146 access(all) fun getAddress() : Address {
147 return self.address
148 }
149 access(all) fun getDescription() : String {
150 return self.description
151 }
152 access(all) fun getExtra() : {String : String} {
153 return {}
154 }
155
156 access(all) fun getPayableLogic() : (fun(UFix64) : UFix64?) {
157 return fun(_ salePrice : UFix64) : UFix64? {
158 let rPayable = salePrice * self.cut
159 if rPayable < self.minimumPayment {
160 return self.minimumPayment
161 }
162 return rPayable
163 }
164 }
165 }
166}
167