@flowtyio/flow-contracts 0.1.0-beta.9 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/contracts/FungibleTokenSwitchboard.cdc +360 -0
- package/contracts/MetadataViews.cdc +79 -6
- package/contracts/NonFungibleToken.cdc +17 -10
- package/contracts/capability-cache/CapabilityCache.cdc +97 -0
- package/contracts/dapper/TopShot.cdc +323 -259
- package/contracts/dapper/TopShotLocking.cdc +41 -15
- package/contracts/dapper/offers/DapperOffersV2.cdc +46 -43
- package/contracts/dapper/offers/OffersV2.cdc +40 -56
- package/contracts/dapper/offers/Resolver.cdc +20 -13
- package/contracts/emerald-city/FLOAT.cdc +259 -254
- package/contracts/evm/CrossVMNFT.cdc +50 -0
- package/contracts/evm/EVM.cdc +851 -0
- package/contracts/evm/FlowEVMBridgeConfig.cdc +454 -0
- package/contracts/evm/FlowEVMBridgeHandlerInterfaces.cdc +163 -0
- package/contracts/evm/FlowEVMBridgeHandlers.cdc +230 -0
- package/contracts/evm/FlowEVMBridgeUtils.cdc +1303 -0
- package/contracts/evm/IBridgePermissions.cdc +19 -0
- package/contracts/evm/ICrossVM.cdc +12 -0
- package/contracts/evm/ICrossVMAsset.cdc +19 -0
- package/contracts/evm/Serialize.cdc +141 -0
- package/contracts/evm/SerializeMetadata.cdc +221 -0
- package/contracts/example/ExampleNFT.cdc +2 -2
- package/contracts/find/FindViews.cdc +357 -353
- package/contracts/flow-utils/ScopedFTProviders.cdc +5 -2
- package/contracts/flow-utils/ScopedNFTProviders.cdc +6 -2
- package/contracts/flowty-drops/ContractManager.cdc +73 -0
- package/contracts/flowty-drops/DropFactory.cdc +75 -0
- package/contracts/flowty-drops/DropTypes.cdc +282 -0
- package/contracts/flowty-drops/FlowtyActiveCheckers.cdc +113 -0
- package/contracts/flowty-drops/FlowtyAddressVerifiers.cdc +64 -0
- package/contracts/flowty-drops/FlowtyDrops.cdc +461 -0
- package/contracts/flowty-drops/FlowtyPricers.cdc +48 -0
- package/contracts/flowty-drops/initializers/ContractBorrower.cdc +14 -0
- package/contracts/flowty-drops/initializers/ContractInitializer.cdc +7 -0
- package/contracts/flowty-drops/initializers/OpenEditionInitializer.cdc +57 -0
- package/contracts/flowty-drops/nft/BaseCollection.cdc +97 -0
- package/contracts/flowty-drops/nft/BaseNFT.cdc +107 -0
- package/contracts/flowty-drops/nft/ContractFactory.cdc +13 -0
- package/contracts/flowty-drops/nft/ContractFactoryTemplate.cdc +48 -0
- package/contracts/flowty-drops/nft/NFTMetadata.cdc +140 -0
- package/contracts/flowty-drops/nft/OpenEditionNFT.cdc +42 -0
- package/contracts/flowty-drops/nft/OpenEditionTemplate.cdc +54 -0
- package/contracts/flowty-drops/nft/UniversalCollection.cdc +29 -0
- package/contracts/fungible-token-router/FungibleTokenRouter.cdc +103 -0
- package/contracts/hybrid-custody/CapabilityDelegator.cdc +28 -26
- package/contracts/hybrid-custody/CapabilityFactory.cdc +20 -18
- package/contracts/hybrid-custody/CapabilityFilter.cdc +41 -24
- package/contracts/hybrid-custody/HybridCustody.cdc +303 -242
- package/contracts/hybrid-custody/factories/FTAllFactory.cdc +16 -4
- package/contracts/hybrid-custody/factories/FTBalanceFactory.cdc +16 -4
- package/contracts/hybrid-custody/factories/FTProviderFactory.cdc +17 -5
- package/contracts/hybrid-custody/factories/FTReceiverBalanceFactory.cdc +16 -4
- package/contracts/hybrid-custody/factories/FTReceiverFactory.cdc +16 -4
- package/contracts/hybrid-custody/factories/FTVaultFactory.cdc +46 -0
- package/contracts/hybrid-custody/factories/NFTCollectionFactory.cdc +45 -0
- package/contracts/hybrid-custody/factories/NFTCollectionPublicFactory.cdc +16 -4
- package/contracts/hybrid-custody/factories/NFTProviderAndCollectionFactory.cdc +22 -0
- package/contracts/hybrid-custody/factories/NFTProviderFactory.cdc +16 -4
- package/contracts/lost-and-found/LostAndFound.cdc +21 -17
- package/contracts/tokens/USDCFlow.cdc +232 -0
- package/flow.json +278 -7
- package/package.json +1 -1
- package/contracts/hybrid-custody/factories/NFTProviderAndCollectionPublicFactory.cdc +0 -10
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import "NonFungibleToken"
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
access(all) contract TopShotLocking {
|
|
4
4
|
|
|
5
5
|
// -----------------------------------------------------------------------
|
|
6
6
|
// TopShotLocking contract Events
|
|
7
7
|
// -----------------------------------------------------------------------
|
|
8
8
|
|
|
9
9
|
// Emitted when a Moment is locked
|
|
10
|
-
|
|
10
|
+
access(all) event MomentLocked(id: UInt64, duration: UFix64, expiryTimestamp: UFix64)
|
|
11
11
|
|
|
12
12
|
// Emitted when a Moment is unlocked
|
|
13
|
-
|
|
13
|
+
access(all) event MomentUnlocked(id: UInt64)
|
|
14
14
|
|
|
15
15
|
// Dictionary of locked NFTs
|
|
16
16
|
// TopShot nft resource id is the key
|
|
@@ -25,7 +25,7 @@ pub contract TopShotLocking {
|
|
|
25
25
|
// Parameters: nftRef: A reference to the NFT resource
|
|
26
26
|
//
|
|
27
27
|
// Returns: true if NFT is locked
|
|
28
|
-
|
|
28
|
+
access(all) view fun isLocked(nftRef: &{NonFungibleToken.NFT}): Bool {
|
|
29
29
|
return self.lockedNFTs.containsKey(nftRef.id)
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -34,7 +34,7 @@ pub contract TopShotLocking {
|
|
|
34
34
|
// Parameters: nftRef: A reference to the NFT resource
|
|
35
35
|
//
|
|
36
36
|
// Returns: unix timestamp
|
|
37
|
-
|
|
37
|
+
access(all) view fun getLockExpiry(nftRef: &{NonFungibleToken.NFT}): UFix64 {
|
|
38
38
|
if !self.lockedNFTs.containsKey(nftRef.id) {
|
|
39
39
|
panic("NFT is not locked")
|
|
40
40
|
}
|
|
@@ -47,7 +47,7 @@ pub contract TopShotLocking {
|
|
|
47
47
|
// duration: number of seconds the NFT will be locked for
|
|
48
48
|
//
|
|
49
49
|
// Returns: the NFT resource
|
|
50
|
-
|
|
50
|
+
access(all) fun lockNFT(nft: @{NonFungibleToken.NFT}, duration: UFix64): @{NonFungibleToken.NFT} {
|
|
51
51
|
let TopShotNFTType: Type = CompositeType("A.TOPSHOTADDRESS.TopShot.NFT")!
|
|
52
52
|
if !nft.isInstance(TopShotNFTType) {
|
|
53
53
|
panic("NFT is not a TopShot NFT")
|
|
@@ -74,7 +74,7 @@ pub contract TopShotLocking {
|
|
|
74
74
|
// Returns: the NFT resource
|
|
75
75
|
//
|
|
76
76
|
// NFT must be eligible for unlocking by an admin
|
|
77
|
-
|
|
77
|
+
access(all) fun unlockNFT(nft: @{NonFungibleToken.NFT}): @{NonFungibleToken.NFT} {
|
|
78
78
|
if !self.lockedNFTs.containsKey(nft.id) {
|
|
79
79
|
// nft is not locked, short circuit and return the nft
|
|
80
80
|
return <- nft
|
|
@@ -101,7 +101,7 @@ pub contract TopShotLocking {
|
|
|
101
101
|
//
|
|
102
102
|
// Returns: array of ids
|
|
103
103
|
//
|
|
104
|
-
|
|
104
|
+
access(all) view fun getIDs(): [UInt64] {
|
|
105
105
|
return self.lockedNFTs.keys
|
|
106
106
|
}
|
|
107
107
|
|
|
@@ -111,7 +111,7 @@ pub contract TopShotLocking {
|
|
|
111
111
|
//
|
|
112
112
|
// Returns: a unix timestamp in seconds
|
|
113
113
|
//
|
|
114
|
-
|
|
114
|
+
access(all) view fun getExpiry(tokenID: UInt64): UFix64? {
|
|
115
115
|
return self.lockedNFTs[tokenID]
|
|
116
116
|
}
|
|
117
117
|
|
|
@@ -119,17 +119,21 @@ pub contract TopShotLocking {
|
|
|
119
119
|
//
|
|
120
120
|
// Returns: an integer containing the number of locked tokens
|
|
121
121
|
//
|
|
122
|
-
|
|
122
|
+
access(all) view fun getLockedNFTsLength(): Int {
|
|
123
123
|
return self.lockedNFTs.length
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
+
// The path to the TopShotLocking Admin resource belonging to the Account
|
|
127
|
+
// which the contract is deployed on
|
|
128
|
+
access(all) view fun AdminStoragePath() : StoragePath { return /storage/TopShotLockingAdmin}
|
|
129
|
+
|
|
126
130
|
// Admin is a special authorization resource that
|
|
127
131
|
// allows the owner to override the lock on a moment
|
|
128
132
|
//
|
|
129
|
-
|
|
133
|
+
access(all) resource Admin {
|
|
130
134
|
// createNewAdmin creates a new Admin resource
|
|
131
135
|
//
|
|
132
|
-
|
|
136
|
+
access(all) fun createNewAdmin(): @Admin {
|
|
133
137
|
return <-create Admin()
|
|
134
138
|
}
|
|
135
139
|
|
|
@@ -137,12 +141,34 @@ pub contract TopShotLocking {
|
|
|
137
141
|
// unlockable, overridding the expiry timestamp
|
|
138
142
|
// the nft owner will still need to send an unlock transaction to unlock
|
|
139
143
|
//
|
|
140
|
-
|
|
144
|
+
access(all) fun markNFTUnlockable(nftRef: &{NonFungibleToken.NFT}) {
|
|
141
145
|
TopShotLocking.unlockableNFTs[nftRef.id] = true
|
|
142
146
|
}
|
|
143
147
|
|
|
148
|
+
access(all) fun unlockByID(id: UInt64) {
|
|
149
|
+
if !TopShotLocking.lockedNFTs.containsKey(id) {
|
|
150
|
+
// nft is not locked, do nothing
|
|
151
|
+
return
|
|
152
|
+
}
|
|
153
|
+
TopShotLocking.lockedNFTs.remove(key: id)
|
|
154
|
+
emit MomentUnlocked(id: id)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// admin may alter the expiry of a lock on an NFT
|
|
158
|
+
access(all) fun setLockExpiryByID(id: UInt64, expiryTimestamp: UFix64) {
|
|
159
|
+
if expiryTimestamp < getCurrentBlock().timestamp {
|
|
160
|
+
panic("cannot set expiry in the past")
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
let duration = expiryTimestamp - getCurrentBlock().timestamp
|
|
164
|
+
|
|
165
|
+
TopShotLocking.lockedNFTs[id] = expiryTimestamp
|
|
166
|
+
|
|
167
|
+
emit MomentLocked(id: id, duration: duration, expiryTimestamp: expiryTimestamp)
|
|
168
|
+
}
|
|
169
|
+
|
|
144
170
|
// unlocks all NFTs
|
|
145
|
-
|
|
171
|
+
access(all) fun unlockAll() {
|
|
146
172
|
TopShotLocking.lockedNFTs = {}
|
|
147
173
|
TopShotLocking.unlockableNFTs = {}
|
|
148
174
|
}
|
|
@@ -160,6 +186,6 @@ pub contract TopShotLocking {
|
|
|
160
186
|
let admin <- create Admin()
|
|
161
187
|
|
|
162
188
|
// Store it in private account storage in `init` so only the admin can use it
|
|
163
|
-
self.account.save(<-admin, to:
|
|
189
|
+
self.account.storage.save(<-admin, to: TopShotLocking.AdminStoragePath())
|
|
164
190
|
}
|
|
165
191
|
}
|
|
@@ -2,6 +2,8 @@ import "OffersV2"
|
|
|
2
2
|
import "FungibleToken"
|
|
3
3
|
import "NonFungibleToken"
|
|
4
4
|
import "Resolver"
|
|
5
|
+
import "ViewResolver"
|
|
6
|
+
|
|
5
7
|
|
|
6
8
|
// DapperOffersV2
|
|
7
9
|
//
|
|
@@ -11,59 +13,62 @@ import "Resolver"
|
|
|
11
13
|
// The DapperOffer resource contains the methods to add, remove, borrow and
|
|
12
14
|
// get details on Offers contained within it.
|
|
13
15
|
//
|
|
14
|
-
|
|
16
|
+
access(all) contract DapperOffersV2 {
|
|
17
|
+
|
|
18
|
+
access(all) entitlement Manager
|
|
19
|
+
access(all) entitlement ProxyManager
|
|
15
20
|
// DapperOffersV2
|
|
16
21
|
// This contract has been deployed.
|
|
17
22
|
// Event consumers can now expect events from this contract.
|
|
18
23
|
//
|
|
19
|
-
|
|
24
|
+
access(all) event DapperOffersInitialized()
|
|
20
25
|
|
|
21
26
|
/// DapperOfferInitialized
|
|
22
27
|
// A DapperOffer resource has been created.
|
|
23
28
|
//
|
|
24
|
-
|
|
29
|
+
access(all) event DapperOfferInitialized(DapperOfferResourceId: UInt64)
|
|
25
30
|
|
|
26
31
|
// DapperOfferDestroyed
|
|
27
32
|
// A DapperOffer resource has been destroyed.
|
|
28
33
|
// Event consumers can now stop processing events from this resource.
|
|
29
34
|
//
|
|
30
|
-
|
|
35
|
+
access(all) event DapperOfferDestroyed(DapperOfferResourceId: UInt64)
|
|
31
36
|
|
|
32
37
|
|
|
33
38
|
// DapperOfferPublic
|
|
34
39
|
// An interface providing a useful public interface to a Offer.
|
|
35
40
|
//
|
|
36
|
-
|
|
41
|
+
access(all) resource interface DapperOfferPublic {
|
|
37
42
|
// getOfferIds
|
|
38
43
|
// Get a list of Offer ids created by the resource.
|
|
39
44
|
//
|
|
40
|
-
|
|
45
|
+
access(all) fun getOfferIds(): [UInt64]
|
|
41
46
|
// borrowOffer
|
|
42
47
|
// Borrow an Offer to either accept the Offer or get details on the Offer.
|
|
43
48
|
//
|
|
44
|
-
|
|
49
|
+
access(all) fun borrowOffer(offerId: UInt64): &{OffersV2.OfferPublic}?
|
|
45
50
|
// cleanup
|
|
46
51
|
// Remove an Offer
|
|
47
52
|
//
|
|
48
|
-
|
|
53
|
+
access(all) fun cleanup(offerId: UInt64)
|
|
49
54
|
// addProxyCapability
|
|
50
55
|
// Assign proxy capabilities (DapperOfferProxyManager) to an DapperOffer resource.
|
|
51
56
|
//
|
|
52
|
-
|
|
57
|
+
access(all) fun addProxyCapability(
|
|
53
58
|
account: Address,
|
|
54
|
-
cap: Capability
|
|
59
|
+
cap: Capability<auth(ProxyManager) &DapperOffer>
|
|
55
60
|
)
|
|
56
61
|
}
|
|
57
62
|
|
|
58
63
|
// DapperOfferManager
|
|
59
64
|
// An interface providing a management interface for an DapperOffer resource.
|
|
60
65
|
//
|
|
61
|
-
|
|
66
|
+
access(all) resource interface DapperOfferManager {
|
|
62
67
|
// createOffer
|
|
63
68
|
// Allows the DapperOffer owner to create Offers.
|
|
64
69
|
//
|
|
65
|
-
|
|
66
|
-
vaultRefCapability: Capability
|
|
70
|
+
access(Manager) fun createOffer(
|
|
71
|
+
vaultRefCapability: Capability<auth(FungibleToken.Withdraw) &{FungibleToken.Vault}>,
|
|
67
72
|
nftReceiverCapability: Capability<&{NonFungibleToken.CollectionPublic}>,
|
|
68
73
|
nftType: Type,
|
|
69
74
|
amount: UFix64,
|
|
@@ -76,21 +81,21 @@ pub contract DapperOffersV2 {
|
|
|
76
81
|
// removeOffer
|
|
77
82
|
// Allows the DapperOffer owner to remove offers
|
|
78
83
|
//
|
|
79
|
-
|
|
84
|
+
access(Manager | ProxyManager) fun removeOffer(offerId: UInt64)
|
|
80
85
|
}
|
|
81
86
|
|
|
82
87
|
// DapperOfferProxyManager
|
|
83
88
|
// An interface providing removeOffer on behalf of an DapperOffer owner.
|
|
84
89
|
//
|
|
85
|
-
|
|
90
|
+
access(all) resource interface DapperOfferProxyManager {
|
|
86
91
|
// removeOffer
|
|
87
92
|
// Allows the DapperOffer owner to remove offers
|
|
88
93
|
//
|
|
89
|
-
|
|
94
|
+
access(Manager | ProxyManager) fun removeOffer(offerId: UInt64)
|
|
90
95
|
// removeOfferFromProxy
|
|
91
96
|
// Allows the DapperOffer proxy owner to remove offers
|
|
92
97
|
//
|
|
93
|
-
|
|
98
|
+
access(ProxyManager) fun removeOfferFromProxy(account: Address, offerId: UInt64)
|
|
94
99
|
}
|
|
95
100
|
|
|
96
101
|
|
|
@@ -98,18 +103,18 @@ pub contract DapperOffersV2 {
|
|
|
98
103
|
// A resource that allows its owner to manage a list of Offers, and anyone to interact with them
|
|
99
104
|
// in order to query their details and accept the Offers for NFTs that they represent.
|
|
100
105
|
//
|
|
101
|
-
|
|
106
|
+
access(all) resource DapperOffer :DapperOfferManager, DapperOfferPublic, DapperOfferProxyManager {
|
|
102
107
|
// The dictionary of Address to DapperOfferProxyManager capabilities.
|
|
103
|
-
access(self) var removeOfferCapability: {Address:Capability
|
|
108
|
+
access(self) var removeOfferCapability: {Address:Capability<auth(ProxyManager) &DapperOffer>}
|
|
104
109
|
// The dictionary of Offer uuids to Offer resources.
|
|
105
110
|
access(self) var offers: @{UInt64:OffersV2.Offer}
|
|
106
111
|
|
|
107
112
|
// addProxyCapability
|
|
108
113
|
// Assign proxy capabilities (DapperOfferProxyManager) to an DapperOffer resource.
|
|
109
114
|
//
|
|
110
|
-
|
|
115
|
+
access(all) fun addProxyCapability(account: Address, cap: Capability<auth(ProxyManager) &DapperOffer>) {
|
|
111
116
|
pre {
|
|
112
|
-
cap
|
|
117
|
+
cap != nil: "Invalid admin capability"
|
|
113
118
|
}
|
|
114
119
|
self.removeOfferCapability[account] = cap
|
|
115
120
|
}
|
|
@@ -117,23 +122,23 @@ pub contract DapperOffersV2 {
|
|
|
117
122
|
// removeOfferFromProxy
|
|
118
123
|
// Allows the DapperOffer proxy owner to remove offers
|
|
119
124
|
//
|
|
120
|
-
|
|
125
|
+
access(ProxyManager) fun removeOfferFromProxy(account: Address, offerId: UInt64) {
|
|
121
126
|
pre {
|
|
122
127
|
self.removeOfferCapability[account] != nil:
|
|
123
128
|
"Cannot remove offers until the token admin has deposited the account registration capability"
|
|
124
129
|
}
|
|
125
130
|
|
|
126
|
-
let adminRef = self.removeOfferCapability[account]
|
|
131
|
+
let adminRef = self.removeOfferCapability[account]!
|
|
127
132
|
|
|
128
|
-
adminRef.removeOffer(offerId: offerId)
|
|
133
|
+
adminRef.borrow()!.removeOffer(offerId: offerId)
|
|
129
134
|
}
|
|
130
135
|
|
|
131
136
|
|
|
132
137
|
// createOffer
|
|
133
138
|
// Allows the DapperOffer owner to create Offers.
|
|
134
139
|
//
|
|
135
|
-
|
|
136
|
-
vaultRefCapability: Capability
|
|
140
|
+
access(Manager) fun createOffer(
|
|
141
|
+
vaultRefCapability: Capability<auth(FungibleToken.Withdraw) &{FungibleToken.Vault}>,
|
|
137
142
|
nftReceiverCapability: Capability<&{NonFungibleToken.CollectionPublic}>,
|
|
138
143
|
nftType: Type,
|
|
139
144
|
amount: UFix64,
|
|
@@ -165,23 +170,25 @@ pub contract DapperOffersV2 {
|
|
|
165
170
|
// removeOffer
|
|
166
171
|
// Remove an Offer that has not yet been accepted from the collection and destroy it.
|
|
167
172
|
//
|
|
168
|
-
|
|
169
|
-
|
|
173
|
+
access(Manager | ProxyManager) fun removeOffer(offerId: UInt64) {
|
|
174
|
+
let offer <- self.offers.remove(key: offerId) ?? panic("missing offer")
|
|
175
|
+
// offer.customDestroy()
|
|
176
|
+
destroy offer
|
|
170
177
|
}
|
|
171
178
|
|
|
172
179
|
// getOfferIds
|
|
173
180
|
// Returns an array of the Offer resource IDs that are in the collection
|
|
174
181
|
//
|
|
175
|
-
|
|
182
|
+
access(all) view fun getOfferIds(): [UInt64] {
|
|
176
183
|
return self.offers.keys
|
|
177
184
|
}
|
|
178
185
|
|
|
179
186
|
// borrowOffer
|
|
180
187
|
// Returns a read-only view of the Offer for the given OfferID if it is contained by this collection.
|
|
181
188
|
//
|
|
182
|
-
|
|
189
|
+
access(all) view fun borrowOffer(offerId: UInt64): &{OffersV2.OfferPublic}? {
|
|
183
190
|
if self.offers[offerId] != nil {
|
|
184
|
-
return (&self.offers[offerId] as &
|
|
191
|
+
return (&self.offers[offerId] as &{OffersV2.OfferPublic}?)!
|
|
185
192
|
} else {
|
|
186
193
|
return nil
|
|
187
194
|
}
|
|
@@ -192,7 +199,7 @@ pub contract DapperOffersV2 {
|
|
|
192
199
|
// Anyone can call, but at present it only benefits the account owner to do so.
|
|
193
200
|
// Kind purchasers can however call it if they like.
|
|
194
201
|
//
|
|
195
|
-
|
|
202
|
+
access(all) fun cleanup(offerId: UInt64) {
|
|
196
203
|
pre {
|
|
197
204
|
self.offers[offerId] != nil: "could not find Offer with given id"
|
|
198
205
|
}
|
|
@@ -210,24 +217,20 @@ pub contract DapperOffersV2 {
|
|
|
210
217
|
emit DapperOfferInitialized(DapperOfferResourceId: self.uuid)
|
|
211
218
|
}
|
|
212
219
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
destroy self.offers
|
|
217
|
-
// Let event consumers know that this storefront exists.
|
|
218
|
-
emit DapperOfferDestroyed(DapperOfferResourceId: self.uuid)
|
|
219
|
-
}
|
|
220
|
+
access(all) event ResourceDestroyed(
|
|
221
|
+
id: UInt64 = self.uuid
|
|
222
|
+
)
|
|
220
223
|
}
|
|
221
224
|
|
|
222
225
|
// createDapperOffer
|
|
223
226
|
// Make creating an DapperOffer publicly accessible.
|
|
224
227
|
//
|
|
225
|
-
|
|
228
|
+
access(all) fun createDapperOffer(): @DapperOffer {
|
|
226
229
|
return <-create DapperOffer()
|
|
227
230
|
}
|
|
228
231
|
|
|
229
|
-
|
|
230
|
-
|
|
232
|
+
access(all) let DapperOffersStoragePath: StoragePath
|
|
233
|
+
access(all) let DapperOffersPublicPath: PublicPath
|
|
231
234
|
|
|
232
235
|
init () {
|
|
233
236
|
self.DapperOffersStoragePath = /storage/DapperOffersV2
|
|
@@ -235,4 +238,4 @@ pub contract DapperOffersV2 {
|
|
|
235
238
|
|
|
236
239
|
emit DapperOffersInitialized()
|
|
237
240
|
}
|
|
238
|
-
}
|
|
241
|
+
}
|
|
@@ -2,9 +2,10 @@ import "FungibleToken"
|
|
|
2
2
|
import "NonFungibleToken"
|
|
3
3
|
import "DapperUtilityCoin"
|
|
4
4
|
import "MetadataViews"
|
|
5
|
+
import "ViewResolver"
|
|
5
6
|
import "Resolver"
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
/// OffersV2
|
|
8
9
|
//
|
|
9
10
|
// Contract holds the Offer resource and a public method to create them.
|
|
10
11
|
//
|
|
@@ -17,12 +18,12 @@ import "Resolver"
|
|
|
17
18
|
// Marketplaces and other aggregators can watch for OfferAvailable events
|
|
18
19
|
// and list offers of interest to logged in users.
|
|
19
20
|
//
|
|
20
|
-
|
|
21
|
+
access(all) contract OffersV2 {
|
|
21
22
|
// OfferAvailable
|
|
22
23
|
// An Offer has been created and added to the users DapperOffer resource.
|
|
23
24
|
//
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
access(all) event OfferAvailable(
|
|
26
27
|
offerAddress: Address,
|
|
27
28
|
offerId: UInt64,
|
|
28
29
|
nftType: Type,
|
|
@@ -39,7 +40,7 @@ pub contract OffersV2 {
|
|
|
39
40
|
// The Offer has been resolved. The offer has either been accepted
|
|
40
41
|
// by the NFT owner, or the offer has been removed and destroyed.
|
|
41
42
|
//
|
|
42
|
-
|
|
43
|
+
access(all) event OfferCompleted(
|
|
43
44
|
purchased: Bool,
|
|
44
45
|
acceptingAddress: Address?,
|
|
45
46
|
offerAddress: Address,
|
|
@@ -59,9 +60,9 @@ pub contract OffersV2 {
|
|
|
59
60
|
// A struct representing a recipient that must be sent a certain amount
|
|
60
61
|
// of the payment when a NFT is sold.
|
|
61
62
|
//
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
access(all) struct Royalty {
|
|
64
|
+
access(all) let receiver: Capability<&{FungibleToken.Receiver}>
|
|
65
|
+
access(all) let amount: UFix64
|
|
65
66
|
|
|
66
67
|
init(receiver: Capability<&{FungibleToken.Receiver}>, amount: UFix64) {
|
|
67
68
|
self.receiver = receiver
|
|
@@ -72,23 +73,23 @@ pub contract OffersV2 {
|
|
|
72
73
|
// OfferDetails
|
|
73
74
|
// A struct containing Offers' data.
|
|
74
75
|
//
|
|
75
|
-
|
|
76
|
+
access(all) struct OfferDetails {
|
|
76
77
|
// The ID of the offer
|
|
77
|
-
|
|
78
|
+
access(all) let offerId: UInt64
|
|
78
79
|
// The Type of the NFT
|
|
79
|
-
|
|
80
|
+
access(all) let nftType: Type
|
|
80
81
|
// The Type of the FungibleToken that payments must be made in.
|
|
81
|
-
|
|
82
|
+
access(all) let paymentVaultType: Type
|
|
82
83
|
// The Offer amount for the NFT
|
|
83
|
-
|
|
84
|
+
access(all) let offerAmount: UFix64
|
|
84
85
|
// Flag to tracked the purchase state
|
|
85
|
-
|
|
86
|
+
access(all) var purchased: Bool
|
|
86
87
|
// This specifies the division of payment between recipients.
|
|
87
|
-
|
|
88
|
+
access(all) let royalties: [Royalty]
|
|
88
89
|
// Used to hold Offer metadata and offer type information
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
access(all) let offerParamsString: {String: String}
|
|
91
|
+
access(all) let offerParamsUFix64: {String:UFix64}
|
|
92
|
+
access(all) let offerParamsUInt64: {String:UInt64}
|
|
92
93
|
|
|
93
94
|
// setToPurchased
|
|
94
95
|
// Irreversibly set this offer as purchased.
|
|
@@ -124,33 +125,37 @@ pub contract OffersV2 {
|
|
|
124
125
|
// OfferPublic
|
|
125
126
|
// An interface providing a useful public interface to an Offer resource.
|
|
126
127
|
//
|
|
127
|
-
|
|
128
|
+
access(all) resource interface OfferPublic {
|
|
128
129
|
// accept
|
|
129
130
|
// This will accept the offer if provided with the NFT id that matches the Offer
|
|
130
131
|
//
|
|
131
|
-
|
|
132
|
-
item: @
|
|
132
|
+
access(all) fun accept(
|
|
133
|
+
item: @{NonFungibleToken.NFT, ViewResolver.Resolver},
|
|
133
134
|
receiverCapability: Capability<&{FungibleToken.Receiver}>,
|
|
134
135
|
): Void
|
|
135
136
|
// getDetails
|
|
136
137
|
// Return Offer details
|
|
137
138
|
//
|
|
138
|
-
|
|
139
|
+
access(all) fun getDetails(): OfferDetails
|
|
139
140
|
}
|
|
140
141
|
|
|
141
142
|
|
|
142
|
-
|
|
143
|
+
access(all) resource Offer: OfferPublic {
|
|
144
|
+
|
|
145
|
+
access(all) event ResourceDestroyed(purchased: Bool = self.details.purchased, offerId: UInt64 = self.details.offerId)
|
|
146
|
+
|
|
147
|
+
|
|
143
148
|
// The OfferDetails struct of the Offer
|
|
144
149
|
access(self) let details: OfferDetails
|
|
145
150
|
// The vault which will handle the payment if the Offer is accepted.
|
|
146
|
-
access(contract) let vaultRefCapability: Capability
|
|
151
|
+
access(contract) let vaultRefCapability: Capability<auth(FungibleToken.Withdraw) &{FungibleToken.Provider, FungibleToken.Balance}>
|
|
147
152
|
// Receiver address for the NFT when/if the Offer is accepted.
|
|
148
153
|
access(contract) let nftReceiverCapability: Capability<&{NonFungibleToken.CollectionPublic}>
|
|
149
154
|
// Resolver capability for the offer type
|
|
150
155
|
access(contract) let resolverCapability: Capability<&{Resolver.ResolverPublic}>
|
|
151
156
|
|
|
152
157
|
init(
|
|
153
|
-
vaultRefCapability: Capability
|
|
158
|
+
vaultRefCapability: Capability<auth(FungibleToken.Withdraw) &{FungibleToken.Vault}>,
|
|
154
159
|
nftReceiverCapability: Capability<&{NonFungibleToken.CollectionPublic}>,
|
|
155
160
|
nftType: Type,
|
|
156
161
|
amount: UFix64,
|
|
@@ -208,8 +213,8 @@ pub contract OffersV2 {
|
|
|
208
213
|
// - Provided with a NFT matching the NFT id within the Offer details.
|
|
209
214
|
// - Provided with a NFT matching the NFT Type within the Offer details.
|
|
210
215
|
//
|
|
211
|
-
|
|
212
|
-
item: @
|
|
216
|
+
access(all) fun accept(
|
|
217
|
+
item: @{NonFungibleToken.NFT, ViewResolver.Resolver},
|
|
213
218
|
receiverCapability: Capability<&{FungibleToken.Receiver}>,
|
|
214
219
|
): Void {
|
|
215
220
|
|
|
@@ -220,7 +225,7 @@ pub contract OffersV2 {
|
|
|
220
225
|
|
|
221
226
|
let resolverCapability = self.resolverCapability.borrow() ?? panic("could not borrow resolver")
|
|
222
227
|
let resolverResult = resolverCapability.checkOfferResolver(
|
|
223
|
-
item: &item as &
|
|
228
|
+
item: &item as &{NonFungibleToken.NFT, ViewResolver.Resolver},
|
|
224
229
|
offerParamsString: self.details.offerParamsString,
|
|
225
230
|
offerParamsUInt64: self.details.offerParamsUInt64,
|
|
226
231
|
offerParamsUFix64: self.details.offerParamsUFix64,
|
|
@@ -231,7 +236,7 @@ pub contract OffersV2 {
|
|
|
231
236
|
}
|
|
232
237
|
|
|
233
238
|
self.details.setToPurchased()
|
|
234
|
-
let nft <- item as! @NonFungibleToken.NFT
|
|
239
|
+
let nft <- item as! @{NonFungibleToken.NFT}
|
|
235
240
|
let nftId: UInt64 = nft.id
|
|
236
241
|
self.nftReceiverCapability.borrow()!.deposit(token: <- nft)
|
|
237
242
|
|
|
@@ -251,8 +256,8 @@ pub contract OffersV2 {
|
|
|
251
256
|
|
|
252
257
|
// If a DUC vault is being used for payment we must assert that no DUC is leaking from the transactions.
|
|
253
258
|
let isDucVault = self.vaultRefCapability.isInstance(
|
|
254
|
-
Type<Capability<&DapperUtilityCoin.Vault
|
|
255
|
-
)
|
|
259
|
+
Type<Capability<&DapperUtilityCoin.Vault>>()
|
|
260
|
+
) // todo: check if this is correct
|
|
256
261
|
|
|
257
262
|
if isDucVault {
|
|
258
263
|
assert(self.vaultRefCapability.borrow()!.balance == initalDucSupply, message: "DUC is leaking")
|
|
@@ -278,14 +283,14 @@ pub contract OffersV2 {
|
|
|
278
283
|
// getDetails
|
|
279
284
|
// Return Offer details
|
|
280
285
|
//
|
|
281
|
-
|
|
286
|
+
access(all) view fun getDetails(): OfferDetails {
|
|
282
287
|
return self.details
|
|
283
288
|
}
|
|
284
289
|
|
|
285
290
|
// getRoyaltyInfo
|
|
286
291
|
// Return royalty details
|
|
287
292
|
//
|
|
288
|
-
|
|
293
|
+
access(all) view fun getRoyaltyInfo(): {Address:UFix64} {
|
|
289
294
|
let royaltyInfo: {Address:UFix64} = {}
|
|
290
295
|
|
|
291
296
|
for royalty in self.details.royalties {
|
|
@@ -293,31 +298,11 @@ pub contract OffersV2 {
|
|
|
293
298
|
}
|
|
294
299
|
return royaltyInfo;
|
|
295
300
|
}
|
|
296
|
-
|
|
297
|
-
destroy() {
|
|
298
|
-
if !self.details.purchased {
|
|
299
|
-
emit OfferCompleted(
|
|
300
|
-
purchased: self.details.purchased,
|
|
301
|
-
acceptingAddress: nil,
|
|
302
|
-
offerAddress: self.nftReceiverCapability.address,
|
|
303
|
-
offerId: self.details.offerId,
|
|
304
|
-
nftType: self.details.nftType,
|
|
305
|
-
offerAmount: self.details.offerAmount,
|
|
306
|
-
royalties: self.getRoyaltyInfo(),
|
|
307
|
-
offerType: self.details.offerParamsString["_type"] ?? "unknown",
|
|
308
|
-
offerParamsString: self.details.offerParamsString,
|
|
309
|
-
offerParamsUFix64: self.details.offerParamsUFix64,
|
|
310
|
-
offerParamsUInt64: self.details.offerParamsUInt64,
|
|
311
|
-
paymentVaultType: self.details.paymentVaultType,
|
|
312
|
-
nftId: nil,
|
|
313
|
-
)
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
301
|
}
|
|
317
302
|
|
|
318
303
|
// makeOffer
|
|
319
|
-
|
|
320
|
-
vaultRefCapability:
|
|
304
|
+
access(all) fun makeOffer(
|
|
305
|
+
vaultRefCapability: Capability<auth(FungibleToken.Withdraw) &{FungibleToken.Vault}>,
|
|
321
306
|
nftReceiverCapability: Capability<&{NonFungibleToken.CollectionPublic}>,
|
|
322
307
|
nftType: Type,
|
|
323
308
|
amount: UFix64,
|
|
@@ -340,5 +325,4 @@ pub contract OffersV2 {
|
|
|
340
325
|
)
|
|
341
326
|
return <-newOfferResource
|
|
342
327
|
}
|
|
343
|
-
}
|
|
344
|
-
|
|
328
|
+
}
|
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
import "NonFungibleToken"
|
|
2
2
|
import "MetadataViews"
|
|
3
3
|
import "TopShot"
|
|
4
|
+
import "ViewResolver"
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
// Resolver
|
|
7
|
+
//
|
|
8
|
+
// Contract holds the Offer exchange resolution rules.
|
|
9
|
+
//
|
|
10
|
+
// When an Offer is created a ResolverType is included. The ResolverType is also
|
|
11
|
+
// passed into checkOfferResolver() from the Offers contract on exchange validation
|
|
12
|
+
access(all) contract Resolver {
|
|
6
13
|
// Current list of supported resolution rules.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
14
|
+
access(all) enum ResolverType: UInt8 {
|
|
15
|
+
access(all) case NFT
|
|
16
|
+
access(all) case TopShotEdition
|
|
17
|
+
access(all) case MetadataViewsEditions
|
|
11
18
|
}
|
|
12
19
|
|
|
13
20
|
// Public resource interface that defines a method signature for checkOfferResolver
|
|
14
21
|
// which is used within the Resolver resource for offer acceptance validation
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
item: &
|
|
22
|
+
access(all) resource interface ResolverPublic {
|
|
23
|
+
access(all) fun checkOfferResolver(
|
|
24
|
+
item: &{NonFungibleToken.NFT, ViewResolver.Resolver},
|
|
18
25
|
offerParamsString: {String:String},
|
|
19
26
|
offerParamsUInt64: {String:UInt64},
|
|
20
27
|
offerParamsUFix64: {String:UFix64}): Bool
|
|
@@ -22,19 +29,19 @@ pub contract Resolver {
|
|
|
22
29
|
|
|
23
30
|
|
|
24
31
|
// Resolver resource holds the Offer exchange resolution rules.
|
|
25
|
-
|
|
32
|
+
access(all) resource OfferResolver: ResolverPublic {
|
|
26
33
|
// checkOfferResolver
|
|
27
34
|
// Holds the validation rules for resolver each type of supported ResolverType
|
|
28
35
|
// Function returns TRUE if the provided nft item passes the criteria for exchange
|
|
29
|
-
|
|
30
|
-
item: &
|
|
36
|
+
access(all) fun checkOfferResolver(
|
|
37
|
+
item: &{NonFungibleToken.NFT, ViewResolver.Resolver},
|
|
31
38
|
offerParamsString: {String:String},
|
|
32
39
|
offerParamsUInt64: {String:UInt64},
|
|
33
40
|
offerParamsUFix64: {String:UFix64}): Bool {
|
|
34
41
|
if offerParamsString["resolver"] == ResolverType.NFT.rawValue.toString() {
|
|
35
42
|
assert(item.id.toString() == offerParamsString["nftId"], message: "item NFT does not have specified ID")
|
|
36
43
|
return true
|
|
37
|
-
}
|
|
44
|
+
} else if offerParamsString["resolver"] == ResolverType.TopShotEdition.rawValue.toString() {
|
|
38
45
|
// // Get the Top Shot specific metadata for this NFT
|
|
39
46
|
let view = item.resolveView(Type<TopShot.TopShotMomentMetadataView>())!
|
|
40
47
|
let metadata = view as! TopShot.TopShotMomentMetadataView
|
|
@@ -64,7 +71,7 @@ pub contract Resolver {
|
|
|
64
71
|
|
|
65
72
|
}
|
|
66
73
|
|
|
67
|
-
|
|
74
|
+
access(all) fun createResolver(): @OfferResolver {
|
|
68
75
|
return <-create OfferResolver()
|
|
69
76
|
}
|
|
70
77
|
}
|