Smart Contract

InfluencerRegistry

A.c38aea683c0c4d38.InfluencerRegistry

Deployed

2h ago
Mar 01, 2026, 05:18:34 PM UTC

Dependents

0 imports
1// The Influencer Registry stores the mappings from the name of an
2// influencer to the vaults in which they'd like to receive tokens,
3// as well as the cut they'd like to take from marketplace transactions.
4
5import FungibleToken from 0xf233dcee88fe0abe
6
7pub contract InfluencerRegistry {
8
9    // Emitted when the contract is created
10    pub event ContractInitialized()
11
12    // Emitted when a FT-receiving capability for an influencer has been updated
13    // If address is nil, that means the capability has been removed.
14    pub event CapabilityUpdated(name: String, ftType: Type, address: Address?)
15
16    // Emitted when an influencer's cut percentage has been updated
17    // If the cutPercentage is nil, that means it has been removed.
18    pub event CutPercentageUpdated(name: String, cutPercentage: UFix64?)
19
20    // Emitted when the default cut percentage has been updated
21    pub event DefaultCutPercentageUpdated(cutPercentage: UFix64?)
22
23    // capabilities is a mapping from influencer name, to fungible token ID, to
24    // the capability for a receiver for the fungible token
25    pub var capabilities: {String: {String: Capability<&{FungibleToken.Receiver}>}}
26
27    // The mappings from the name of an influencer to the cut percentage
28    // that they are supposed to receive.
29    pub var cutPercentages: {String: UFix64}
30
31    // The default cut percentage
32    pub var defaultCutPercentage: UFix64
33
34    // Get the capability for depositing accounting tokens to the influencer
35    pub fun getCapability(name: String, ftType: Type): Capability? {
36        let ftId = ftType.identifier
37
38        if let caps = self.capabilities[name] {
39            return caps[ftId]
40        } else {
41            return nil
42        }
43    }
44
45    // Get the current cut percentage for the influencer
46    pub fun getCutPercentage(name: String): UFix64 {
47        if let cut = InfluencerRegistry.cutPercentages[name] {
48            return cut
49        } else {
50            return InfluencerRegistry.defaultCutPercentage
51        }
52    }
53
54    // Admin is an authorization resource that allows the contract owner to 
55    // update values in the registry.
56    pub resource Admin {
57
58        // Update the FT-receiving capability for an influencer
59        pub fun setCapability(name: String, ftType: Type, capability: Capability<&{FungibleToken.Receiver}>?) {
60            let ftId = ftType.identifier
61            if let cap = capability {
62                if let caps = InfluencerRegistry.capabilities[name] {
63                    caps[ftId] = cap
64                    InfluencerRegistry.capabilities[name] = caps
65                } else {
66                    InfluencerRegistry.capabilities[name] = {ftId: cap}
67                }
68                // This is the only way to get the address behind a capability from Cadence right
69                // now.  It will panic if the capability is not pointing to anything, but in that
70                // case we should in fact panic anyways.
71                let addr = ((cap.borrow() ?? panic("Capability is empty"))
72                    .owner ?? panic("Capability owner is empty"))
73                    .address
74
75                emit CapabilityUpdated(name: name, ftType: ftType, address: addr)
76            } else {
77                if let caps = InfluencerRegistry.capabilities[name] {
78                    caps.remove(key: ftId)
79                    InfluencerRegistry.capabilities[name] = caps
80                }
81
82                emit CapabilityUpdated(name: name, ftType: ftType, address: nil)
83            }
84        }
85
86        // Update the cut percentage for the influencer
87        pub fun setCutPercentage(name: String, cutPercentage: UFix64?) {
88            InfluencerRegistry.cutPercentages[name] = cutPercentage
89
90            emit CutPercentageUpdated(name: name, cutPercentage: cutPercentage)
91        }
92
93        // Update the default cut percentage
94        pub fun setDefaultCutPercentage(cutPercentage: UFix64) {
95            InfluencerRegistry.defaultCutPercentage = cutPercentage
96            emit DefaultCutPercentageUpdated(cutPercentage: cutPercentage)
97        }
98
99    }
100
101    init() {
102        self.cutPercentages = {}
103        self.capabilities = {}
104
105        self.defaultCutPercentage = 0.04
106
107        self.account.save<@Admin>(<- create Admin(), to: /storage/EternalInfluencerRegistryAdmin)
108    }
109
110}
111