@flowtyio/flow-contracts 0.1.0-beta.2 → 0.1.0-beta.21
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/contracts/Burner.cdc +44 -0
- package/contracts/FlowStorageFees.cdc +15 -15
- package/contracts/FlowToken.cdc +29 -78
- package/contracts/FungibleToken.cdc +80 -53
- package/contracts/FungibleTokenMetadataViews.cdc +13 -25
- package/contracts/MetadataViews.cdc +107 -50
- package/contracts/NonFungibleToken.cdc +110 -60
- package/contracts/TokenForwarding.cdc +19 -11
- package/contracts/ViewResolver.cdc +20 -16
- package/contracts/dapper/DapperUtilityCoin.cdc +106 -39
- package/contracts/dapper/FlowUtilityToken.cdc +107 -40
- package/contracts/dapper/TopShot.cdc +323 -259
- package/contracts/dapper/TopShotLocking.cdc +41 -15
- package/contracts/dapper/offers/DapperOffersV2.cdc +36 -40
- package/contracts/dapper/offers/OffersV2.cdc +52 -51
- package/contracts/dapper/offers/Resolver.cdc +13 -12
- package/contracts/emerald-city/FLOAT.cdc +259 -254
- package/contracts/example/ExampleNFT.cdc +419 -0
- package/contracts/example/ExampleToken.cdc +302 -0
- package/contracts/find/FindViews.cdc +357 -353
- package/contracts/flow-utils/AddressUtils.cdc +20 -23
- package/contracts/flow-utils/ArrayUtils.cdc +10 -11
- package/contracts/flow-utils/ScopedFTProviders.cdc +27 -19
- package/contracts/flow-utils/ScopedNFTProviders.cdc +31 -26
- package/contracts/flow-utils/StringUtils.cdc +24 -37
- package/contracts/hybrid-custody/CapabilityDelegator.cdc +29 -26
- package/contracts/hybrid-custody/CapabilityFactory.cdc +21 -18
- package/contracts/hybrid-custody/CapabilityFilter.cdc +42 -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 +45 -0
- package/contracts/hybrid-custody/factories/NFTCollectionFactory.cdc +45 -0
- package/contracts/hybrid-custody/factories/NFTCollectionPublicFactory.cdc +16 -4
- package/contracts/hybrid-custody/factories/NFTProviderAndCollectionPublicFactory.cdc +16 -4
- package/contracts/hybrid-custody/factories/NFTProviderFactory.cdc +16 -4
- package/contracts/lost-and-found/LostAndFound.cdc +14 -14
- package/contracts/nft-catalog/NFTCatalog.cdc +60 -64
- package/contracts/nft-catalog/NFTCatalogAdmin.cdc +28 -27
- package/flow.json +38 -1
- package/package.json +1 -1
|
@@ -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
|
}
|
|
@@ -11,59 +11,59 @@ import "Resolver"
|
|
|
11
11
|
// The DapperOffer resource contains the methods to add, remove, borrow and
|
|
12
12
|
// get details on Offers contained within it.
|
|
13
13
|
//
|
|
14
|
-
|
|
14
|
+
access(all) contract DapperOffersV2 {
|
|
15
15
|
// DapperOffersV2
|
|
16
16
|
// This contract has been deployed.
|
|
17
17
|
// Event consumers can now expect events from this contract.
|
|
18
18
|
//
|
|
19
|
-
|
|
19
|
+
access(all) event DapperOffersInitialized()
|
|
20
20
|
|
|
21
21
|
/// DapperOfferInitialized
|
|
22
22
|
// A DapperOffer resource has been created.
|
|
23
23
|
//
|
|
24
|
-
|
|
24
|
+
access(all) event DapperOfferInitialized(DapperOfferResourceId: UInt64)
|
|
25
25
|
|
|
26
26
|
// DapperOfferDestroyed
|
|
27
27
|
// A DapperOffer resource has been destroyed.
|
|
28
28
|
// Event consumers can now stop processing events from this resource.
|
|
29
29
|
//
|
|
30
|
-
|
|
30
|
+
access(all) event DapperOfferDestroyed(DapperOfferResourceId: UInt64)
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
// DapperOfferPublic
|
|
34
34
|
// An interface providing a useful public interface to a Offer.
|
|
35
35
|
//
|
|
36
|
-
|
|
36
|
+
access(all) resource interface DapperOfferPublic {
|
|
37
37
|
// getOfferIds
|
|
38
38
|
// Get a list of Offer ids created by the resource.
|
|
39
39
|
//
|
|
40
|
-
|
|
40
|
+
access(all) fun getOfferIds(): [UInt64]
|
|
41
41
|
// borrowOffer
|
|
42
42
|
// Borrow an Offer to either accept the Offer or get details on the Offer.
|
|
43
43
|
//
|
|
44
|
-
|
|
44
|
+
access(all) fun borrowOffer(offerId: UInt64): &{OffersV2.OfferPublic}?
|
|
45
45
|
// cleanup
|
|
46
46
|
// Remove an Offer
|
|
47
47
|
//
|
|
48
|
-
|
|
48
|
+
access(all) fun cleanup(offerId: UInt64)
|
|
49
49
|
// addProxyCapability
|
|
50
50
|
// Assign proxy capabilities (DapperOfferProxyManager) to an DapperOffer resource.
|
|
51
51
|
//
|
|
52
|
-
|
|
52
|
+
access(all) fun addProxyCapability(
|
|
53
53
|
account: Address,
|
|
54
|
-
cap: Capability<&
|
|
54
|
+
cap: Capability<&{DapperOffersV2.DapperOfferProxyManager}>
|
|
55
55
|
)
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
// DapperOfferManager
|
|
59
59
|
// An interface providing a management interface for an DapperOffer resource.
|
|
60
60
|
//
|
|
61
|
-
|
|
61
|
+
access(all) resource interface DapperOfferManager {
|
|
62
62
|
// createOffer
|
|
63
63
|
// Allows the DapperOffer owner to create Offers.
|
|
64
64
|
//
|
|
65
|
-
|
|
66
|
-
vaultRefCapability: Capability
|
|
65
|
+
access(all) fun createOffer(
|
|
66
|
+
vaultRefCapability: Capability<auth(FungibleToken.Withdraw) &{FungibleToken.Provider, FungibleToken.Balance}>,
|
|
67
67
|
nftReceiverCapability: Capability<&{NonFungibleToken.CollectionPublic}>,
|
|
68
68
|
nftType: Type,
|
|
69
69
|
amount: UFix64,
|
|
@@ -76,21 +76,21 @@ pub contract DapperOffersV2 {
|
|
|
76
76
|
// removeOffer
|
|
77
77
|
// Allows the DapperOffer owner to remove offers
|
|
78
78
|
//
|
|
79
|
-
|
|
79
|
+
access(all) fun removeOffer(offerId: UInt64)
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
// DapperOfferProxyManager
|
|
83
83
|
// An interface providing removeOffer on behalf of an DapperOffer owner.
|
|
84
84
|
//
|
|
85
|
-
|
|
85
|
+
access(all) resource interface DapperOfferProxyManager {
|
|
86
86
|
// removeOffer
|
|
87
87
|
// Allows the DapperOffer owner to remove offers
|
|
88
88
|
//
|
|
89
|
-
|
|
89
|
+
access(all) fun removeOffer(offerId: UInt64)
|
|
90
90
|
// removeOfferFromProxy
|
|
91
91
|
// Allows the DapperOffer proxy owner to remove offers
|
|
92
92
|
//
|
|
93
|
-
|
|
93
|
+
access(all) fun removeOfferFromProxy(account: Address, offerId: UInt64)
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
|
|
@@ -98,16 +98,16 @@ pub contract DapperOffersV2 {
|
|
|
98
98
|
// A resource that allows its owner to manage a list of Offers, and anyone to interact with them
|
|
99
99
|
// in order to query their details and accept the Offers for NFTs that they represent.
|
|
100
100
|
//
|
|
101
|
-
|
|
101
|
+
access(all) resource DapperOffer : DapperOfferManager, DapperOfferPublic, DapperOfferProxyManager {
|
|
102
102
|
// The dictionary of Address to DapperOfferProxyManager capabilities.
|
|
103
|
-
access(self) var removeOfferCapability: {Address:Capability<&
|
|
103
|
+
access(self) var removeOfferCapability: {Address:Capability<&{DapperOffersV2.DapperOfferProxyManager}>}
|
|
104
104
|
// The dictionary of Offer uuids to Offer resources.
|
|
105
105
|
access(self) var offers: @{UInt64:OffersV2.Offer}
|
|
106
106
|
|
|
107
107
|
// addProxyCapability
|
|
108
108
|
// Assign proxy capabilities (DapperOfferProxyManager) to an DapperOffer resource.
|
|
109
109
|
//
|
|
110
|
-
|
|
110
|
+
access(all) fun addProxyCapability(account: Address, cap: Capability<&{DapperOffersV2.DapperOfferProxyManager}>) {
|
|
111
111
|
pre {
|
|
112
112
|
cap.borrow() != nil: "Invalid admin capability"
|
|
113
113
|
}
|
|
@@ -117,7 +117,7 @@ pub contract DapperOffersV2 {
|
|
|
117
117
|
// removeOfferFromProxy
|
|
118
118
|
// Allows the DapperOffer proxy owner to remove offers
|
|
119
119
|
//
|
|
120
|
-
|
|
120
|
+
access(all) fun removeOfferFromProxy(account: Address, offerId: UInt64) {
|
|
121
121
|
pre {
|
|
122
122
|
self.removeOfferCapability[account] != nil:
|
|
123
123
|
"Cannot remove offers until the token admin has deposited the account registration capability"
|
|
@@ -132,8 +132,8 @@ pub contract DapperOffersV2 {
|
|
|
132
132
|
// createOffer
|
|
133
133
|
// Allows the DapperOffer owner to create Offers.
|
|
134
134
|
//
|
|
135
|
-
|
|
136
|
-
vaultRefCapability: Capability
|
|
135
|
+
access(all) fun createOffer(
|
|
136
|
+
vaultRefCapability: Capability<auth(FungibleToken.Withdraw) &{FungibleToken.Provider, FungibleToken.Balance}>,
|
|
137
137
|
nftReceiverCapability: Capability<&{NonFungibleToken.CollectionPublic}>,
|
|
138
138
|
nftType: Type,
|
|
139
139
|
amount: UFix64,
|
|
@@ -165,26 +165,22 @@ pub contract DapperOffersV2 {
|
|
|
165
165
|
// removeOffer
|
|
166
166
|
// Remove an Offer that has not yet been accepted from the collection and destroy it.
|
|
167
167
|
//
|
|
168
|
-
|
|
168
|
+
access(all) fun removeOffer(offerId: UInt64) {
|
|
169
169
|
destroy self.offers.remove(key: offerId) ?? panic("missing offer")
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
// getOfferIds
|
|
173
173
|
// Returns an array of the Offer resource IDs that are in the collection
|
|
174
174
|
//
|
|
175
|
-
|
|
175
|
+
access(all) fun getOfferIds(): [UInt64] {
|
|
176
176
|
return self.offers.keys
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
// borrowOffer
|
|
180
180
|
// Returns a read-only view of the Offer for the given OfferID if it is contained by this collection.
|
|
181
181
|
//
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
return (&self.offers[offerId] as &OffersV2.Offer{OffersV2.OfferPublic}?)!
|
|
185
|
-
} else {
|
|
186
|
-
return nil
|
|
187
|
-
}
|
|
182
|
+
access(all) fun borrowOffer(offerId: UInt64): &{OffersV2.OfferPublic}? {
|
|
183
|
+
return &self.offers[offerId]
|
|
188
184
|
}
|
|
189
185
|
|
|
190
186
|
// cleanup
|
|
@@ -192,7 +188,7 @@ pub contract DapperOffersV2 {
|
|
|
192
188
|
// Anyone can call, but at present it only benefits the account owner to do so.
|
|
193
189
|
// Kind purchasers can however call it if they like.
|
|
194
190
|
//
|
|
195
|
-
|
|
191
|
+
access(all) fun cleanup(offerId: UInt64) {
|
|
196
192
|
pre {
|
|
197
193
|
self.offers[offerId] != nil: "could not find Offer with given id"
|
|
198
194
|
}
|
|
@@ -212,22 +208,22 @@ pub contract DapperOffersV2 {
|
|
|
212
208
|
|
|
213
209
|
// destructor
|
|
214
210
|
//
|
|
215
|
-
destroy() {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
211
|
+
// destroy() {
|
|
212
|
+
// destroy self.offers
|
|
213
|
+
// // Let event consumers know that this storefront exists.
|
|
214
|
+
// emit DapperOfferDestroyed(DapperOfferResourceId: self.uuid)
|
|
215
|
+
// }
|
|
220
216
|
}
|
|
221
217
|
|
|
222
218
|
// createDapperOffer
|
|
223
219
|
// Make creating an DapperOffer publicly accessible.
|
|
224
220
|
//
|
|
225
|
-
|
|
221
|
+
access(all) fun createDapperOffer(): @DapperOffer {
|
|
226
222
|
return <-create DapperOffer()
|
|
227
223
|
}
|
|
228
224
|
|
|
229
|
-
|
|
230
|
-
|
|
225
|
+
access(all) let DapperOffersStoragePath: StoragePath
|
|
226
|
+
access(all) let DapperOffersPublicPath: PublicPath
|
|
231
227
|
|
|
232
228
|
init () {
|
|
233
229
|
self.DapperOffersStoragePath = /storage/DapperOffersV2
|
|
@@ -3,6 +3,7 @@ import "NonFungibleToken"
|
|
|
3
3
|
import "DapperUtilityCoin"
|
|
4
4
|
import "MetadataViews"
|
|
5
5
|
import "Resolver"
|
|
6
|
+
import "ViewResolver"
|
|
6
7
|
|
|
7
8
|
// OffersV2
|
|
8
9
|
//
|
|
@@ -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,33 @@ 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 {
|
|
143
144
|
// The OfferDetails struct of the Offer
|
|
144
145
|
access(self) let details: OfferDetails
|
|
145
146
|
// The vault which will handle the payment if the Offer is accepted.
|
|
146
|
-
access(contract) let vaultRefCapability: Capability
|
|
147
|
+
access(contract) let vaultRefCapability: Capability<auth(FungibleToken.Withdraw) &{FungibleToken.Provider, FungibleToken.Balance}>
|
|
147
148
|
// Receiver address for the NFT when/if the Offer is accepted.
|
|
148
149
|
access(contract) let nftReceiverCapability: Capability<&{NonFungibleToken.CollectionPublic}>
|
|
149
150
|
// Resolver capability for the offer type
|
|
150
151
|
access(contract) let resolverCapability: Capability<&{Resolver.ResolverPublic}>
|
|
151
152
|
|
|
152
153
|
init(
|
|
153
|
-
vaultRefCapability: Capability
|
|
154
|
+
vaultRefCapability: Capability<auth(FungibleToken.Withdraw) &{FungibleToken.Provider, FungibleToken.Balance}>,
|
|
154
155
|
nftReceiverCapability: Capability<&{NonFungibleToken.CollectionPublic}>,
|
|
155
156
|
nftType: Type,
|
|
156
157
|
amount: UFix64,
|
|
@@ -208,8 +209,8 @@ pub contract OffersV2 {
|
|
|
208
209
|
// - Provided with a NFT matching the NFT id within the Offer details.
|
|
209
210
|
// - Provided with a NFT matching the NFT Type within the Offer details.
|
|
210
211
|
//
|
|
211
|
-
|
|
212
|
-
item: @
|
|
212
|
+
access(all) fun accept(
|
|
213
|
+
item: @{NonFungibleToken.NFT, ViewResolver.Resolver},
|
|
213
214
|
receiverCapability: Capability<&{FungibleToken.Receiver}>,
|
|
214
215
|
): Void {
|
|
215
216
|
|
|
@@ -220,7 +221,7 @@ pub contract OffersV2 {
|
|
|
220
221
|
|
|
221
222
|
let resolverCapability = self.resolverCapability.borrow() ?? panic("could not borrow resolver")
|
|
222
223
|
let resolverResult = resolverCapability.checkOfferResolver(
|
|
223
|
-
item: &item as &
|
|
224
|
+
item: &item as &{NonFungibleToken.NFT, ViewResolver.Resolver},
|
|
224
225
|
offerParamsString: self.details.offerParamsString,
|
|
225
226
|
offerParamsUInt64: self.details.offerParamsUInt64,
|
|
226
227
|
offerParamsUFix64: self.details.offerParamsUFix64,
|
|
@@ -231,7 +232,7 @@ pub contract OffersV2 {
|
|
|
231
232
|
}
|
|
232
233
|
|
|
233
234
|
self.details.setToPurchased()
|
|
234
|
-
let nft <- item as! @NonFungibleToken.NFT
|
|
235
|
+
let nft <- item as! @{NonFungibleToken.NFT}
|
|
235
236
|
let nftId: UInt64 = nft.id
|
|
236
237
|
self.nftReceiverCapability.borrow()!.deposit(token: <- nft)
|
|
237
238
|
|
|
@@ -251,7 +252,7 @@ pub contract OffersV2 {
|
|
|
251
252
|
|
|
252
253
|
// If a DUC vault is being used for payment we must assert that no DUC is leaking from the transactions.
|
|
253
254
|
let isDucVault = self.vaultRefCapability.isInstance(
|
|
254
|
-
Type<Capability<&
|
|
255
|
+
Type<Capability<&{FungibleToken.Provider, FungibleToken.Balance}>>()
|
|
255
256
|
)
|
|
256
257
|
|
|
257
258
|
if isDucVault {
|
|
@@ -278,14 +279,14 @@ pub contract OffersV2 {
|
|
|
278
279
|
// getDetails
|
|
279
280
|
// Return Offer details
|
|
280
281
|
//
|
|
281
|
-
|
|
282
|
+
access(all) fun getDetails(): OfferDetails {
|
|
282
283
|
return self.details
|
|
283
284
|
}
|
|
284
285
|
|
|
285
286
|
// getRoyaltyInfo
|
|
286
287
|
// Return royalty details
|
|
287
288
|
//
|
|
288
|
-
|
|
289
|
+
access(all) fun getRoyaltyInfo(): {Address:UFix64} {
|
|
289
290
|
let royaltyInfo: {Address:UFix64} = {}
|
|
290
291
|
|
|
291
292
|
for royalty in self.details.royalties {
|
|
@@ -294,30 +295,30 @@ pub contract OffersV2 {
|
|
|
294
295
|
return royaltyInfo;
|
|
295
296
|
}
|
|
296
297
|
|
|
297
|
-
destroy() {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
}
|
|
298
|
+
// destroy() {
|
|
299
|
+
// if !self.details.purchased {
|
|
300
|
+
// emit OfferCompleted(
|
|
301
|
+
// purchased: self.details.purchased,
|
|
302
|
+
// acceptingAddress: nil,
|
|
303
|
+
// offerAddress: self.nftReceiverCapability.address,
|
|
304
|
+
// offerId: self.details.offerId,
|
|
305
|
+
// nftType: self.details.nftType,
|
|
306
|
+
// offerAmount: self.details.offerAmount,
|
|
307
|
+
// royalties: self.getRoyaltyInfo(),
|
|
308
|
+
// offerType: self.details.offerParamsString["_type"] ?? "unknown",
|
|
309
|
+
// offerParamsString: self.details.offerParamsString,
|
|
310
|
+
// offerParamsUFix64: self.details.offerParamsUFix64,
|
|
311
|
+
// offerParamsUInt64: self.details.offerParamsUInt64,
|
|
312
|
+
// paymentVaultType: self.details.paymentVaultType,
|
|
313
|
+
// nftId: nil,
|
|
314
|
+
// )
|
|
315
|
+
// }
|
|
316
|
+
// }
|
|
316
317
|
}
|
|
317
318
|
|
|
318
319
|
// makeOffer
|
|
319
|
-
|
|
320
|
-
vaultRefCapability: Capability
|
|
320
|
+
access(all) fun makeOffer(
|
|
321
|
+
vaultRefCapability: Capability<auth(FungibleToken.Withdraw) &{FungibleToken.Provider, FungibleToken.Balance}>,
|
|
321
322
|
nftReceiverCapability: Capability<&{NonFungibleToken.CollectionPublic}>,
|
|
322
323
|
nftType: Type,
|
|
323
324
|
amount: UFix64,
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import "NonFungibleToken"
|
|
2
2
|
import "MetadataViews"
|
|
3
|
+
import "ViewResolver"
|
|
3
4
|
import "TopShot"
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
access(all) contract Resolver {
|
|
6
7
|
// Current list of supported resolution rules.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
access(all) enum ResolverType: UInt8 {
|
|
9
|
+
access(all) case NFT
|
|
10
|
+
access(all) case TopShotEdition
|
|
11
|
+
access(all) case MetadataViewsEditions
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
// Public resource interface that defines a method signature for checkOfferResolver
|
|
14
15
|
// which is used within the Resolver resource for offer acceptance validation
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
item: &
|
|
16
|
+
access(all) resource interface ResolverPublic {
|
|
17
|
+
access(all) fun checkOfferResolver(
|
|
18
|
+
item: &{NonFungibleToken.NFT, ViewResolver.Resolver},
|
|
18
19
|
offerParamsString: {String:String},
|
|
19
20
|
offerParamsUInt64: {String:UInt64},
|
|
20
21
|
offerParamsUFix64: {String:UFix64}): Bool
|
|
@@ -22,12 +23,12 @@ pub contract Resolver {
|
|
|
22
23
|
|
|
23
24
|
|
|
24
25
|
// Resolver resource holds the Offer exchange resolution rules.
|
|
25
|
-
|
|
26
|
+
access(all) resource OfferResolver: ResolverPublic {
|
|
26
27
|
// checkOfferResolver
|
|
27
28
|
// Holds the validation rules for resolver each type of supported ResolverType
|
|
28
29
|
// Function returns TRUE if the provided nft item passes the criteria for exchange
|
|
29
|
-
|
|
30
|
-
item: &
|
|
30
|
+
access(all) fun checkOfferResolver(
|
|
31
|
+
item: &{NonFungibleToken.NFT, ViewResolver.Resolver},
|
|
31
32
|
offerParamsString: {String:String},
|
|
32
33
|
offerParamsUInt64: {String:UInt64},
|
|
33
34
|
offerParamsUFix64: {String:UFix64}): Bool {
|
|
@@ -64,7 +65,7 @@ pub contract Resolver {
|
|
|
64
65
|
|
|
65
66
|
}
|
|
66
67
|
|
|
67
|
-
|
|
68
|
+
access(all) fun createResolver(): @OfferResolver {
|
|
68
69
|
return <-create OfferResolver()
|
|
69
70
|
}
|
|
70
71
|
}
|