Smart Contract
Pistis
A.67c649092019e032.Pistis
1// MADE BY: Noah Naizir
2
3// This contract is for Pistis, a proof of support platform
4// built on Flow.
5
6// Pistis (Πίστις) is not a goddess in the traditional Olympian sense
7// but rather a personified spirit (daimona) representing:
8// Good Faith, Trust, Loyalty and Reliability
9
10// She is the embodiment of belief between people
11// the social and moral glue of contracts, pacts, and promises.
12// In early Greek society, Pistis wasn't just religious faith —
13// it was interpersonal and civic trust.
14
15// Pistis is a proof-of-support protocol where:
16
17// Collectors pledge soulbound tokens as a form of trust in creators. (Pledged trust/faith)
18// Artists distribute rewards in return, honoring loyalty. (Proof of loyalty & belief)
19// Multipliers reflect belief over time, rewarding early conviction. (Honoring those who believed)
20// It's a trust economy based on On—chain Provenance and that's exactly what Pistis governs.
21
22import FungibleToken from 0xf233dcee88fe0abe
23import FlowToken from 0x1654653399040a61
24import NonFungibleToken from 0x1d7e57aa55817448
25import ViewResolver from 0x1d7e57aa55817448
26import MetadataViews from 0x1d7e57aa55817448
27
28
29// Right now, I just need this interface to manage an NFT as a pool
30
31// For that, I need the resource to hold a Token Vault (as the pool)
32access(all)
33contract interface Pistis {
34
35 access(all) event LoyaltyAdded(address: Address, loyaltyPoints: UFix64)
36
37 // access(all) entitlement Withdraw
38
39 /**
40 * The Pool is a resource that holds a dictionary of vaults
41 * and a dictionary of vault receiver paths
42 * it also has a function to add a vault to the dictionary
43 * and a function to deposit to a vault
44 * and a function to withdraw from a vault
45 */
46
47 access(all) resource interface Loyalty {
48 access(all) var loyaltyPoints: {Address: UFix64}
49
50 access(all) fun addLoyalty(address: Address, loyaltyPoints: UFix64) {
51 if self.loyaltyPoints[address] == nil {
52 self.loyaltyPoints[address] = 0.0
53 }
54 self.loyaltyPoints[address] = self.loyaltyPoints[address]! + loyaltyPoints
55 emit LoyaltyAdded(address: address, loyaltyPoints: loyaltyPoints)
56 }
57
58 access(all) fun substractLoyalty(address: Address, loyaltyPoints: UFix64) {
59 self.loyaltyPoints[address] = self.loyaltyPoints[address]! - loyaltyPoints
60 }
61
62 access(all) fun getLoyalty(address: Address): UFix64 {
63 return self.loyaltyPoints[address]!
64 }
65
66 access(all) fun getLoyaltyPoints(): {Address: UFix64} {
67 return self.loyaltyPoints
68 }
69
70 access(all) fun getLoyaltyPointsByAddress(address: Address): UFix64 {
71 return self.loyaltyPoints[address]!
72 }
73
74
75 }
76
77
78 access(all) resource interface Pool {
79 access(all) var vaultsDict: @{Type: {FungibleToken.Vault}}
80 // store the vault receiver reference
81 access(all) var vaultReceiverPath: {Type: PublicPath}
82
83 access(all) fun addVault(vaultType: Type, vault: @{FungibleToken.Vault}, vaultReceiverPath: PublicPath) {
84 pre {
85 vaultType.isSubtype(of: Type<@{FungibleToken.Vault}>()) == true: "Type is not a subtype of FungibleToken.Vault"
86 }
87
88 let oldVault <- self.vaultsDict[vaultType] <- vault
89 self.vaultReceiverPath[vaultType] = vaultReceiverPath
90 destroy oldVault
91 }
92
93 access(all) view fun getVaultTypes(): [Type] {
94
95 return self.vaultsDict.keys
96 }
97
98 // function to deposit
99 access(all) fun depositToVault( vaultType: Type, vaultDeposit: @{FungibleToken.Vault}) {
100 pre {
101 self.vaultsDict[vaultType] != nil: "There's no vault of this type"
102 }
103 let vault <- self.vaultsDict.remove(key: vaultType)!
104 vault.deposit(from: <- vaultDeposit.withdraw(amount: vaultDeposit.balance))
105 self.vaultsDict[vaultType] <-! vault
106
107 destroy vaultDeposit
108 }
109
110 access(all) fun withdrawFromVault(id: UInt64, vaultType: Type): @{PublicPath: {FungibleToken.Vault}} {
111 pre {
112 self.vaultsDict[vaultType] != nil: "There's no vault of this type"
113 }
114
115 let oldVault <- self.vaultsDict.remove(key: vaultType)!
116
117 let newVault <- oldVault.withdraw(amount: oldVault.balance)
118 // return the old vault to the dictionary
119 self.vaultsDict[vaultType] <-! oldVault
120 let result: @{PublicPath: {FungibleToken.Vault}} <- {}
121 result[self.vaultReceiverPath[vaultType]!] <-! newVault
122
123 return <- result
124 }
125 }
126
127}