Smart Contract
GaiaFee
A.8b148183c28ff88f.GaiaFee
1// Gaia Fees
2//
3// Simple fee manager
4//
5pub contract GaiaFee {
6
7 pub let commonFeeManagerStoragePath: StoragePath
8
9 pub event SellerFeeChanged(value: UFix64)
10 pub event BuyerFeeChanged(value: UFix64)
11 pub event FeeAddressUpdated(label: String, address: Address)
12
13 access(self) var feeAddresses: {String:Address}
14
15 // Seller fee [0..1)
16 pub var sellerFee: UFix64
17
18 // BuyerFee fee [0..1)
19 pub var buyerFee: UFix64
20
21 pub resource Manager {
22 pub fun setSellerFee(_ fee: UFix64) {
23 GaiaFee.sellerFee = fee
24 emit SellerFeeChanged(value: GaiaFee.sellerFee)
25 }
26
27 pub fun setBuyerFee(_ fee: UFix64) {
28 GaiaFee.buyerFee = fee
29 emit BuyerFeeChanged(value: GaiaFee.buyerFee)
30 }
31
32 pub fun setFeeAddress(_ label: String, address: Address) {
33 GaiaFee.feeAddresses[label] = address
34 emit FeeAddressUpdated(label: label, address: address)
35 }
36 }
37
38 init() {
39 self.sellerFee = 0.05
40 emit SellerFeeChanged(value: GaiaFee.sellerFee)
41 self.buyerFee = 0.0 // Gaia Buyer Fee
42 emit BuyerFeeChanged(value: GaiaFee.buyerFee)
43
44 self.feeAddresses = {}
45
46 self.commonFeeManagerStoragePath = /storage/commonFeeManager
47 self.account.save(<- create Manager(), to: self.commonFeeManagerStoragePath)
48 }
49
50 pub fun feeAddress(): Address {
51 return self.feeAddresses["gaia"] ?? self.account.address
52 }
53
54 pub fun feeAddressByName(_ label: String): Address {
55 return self.feeAddresses[label] ?? self.account.address
56 }
57
58 pub fun addressMap(): {String:Address} {
59 return GaiaFee.feeAddresses
60 }
61}
62