@silvana-one/nft 0.1.22 → 0.1.24
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/dist/node/contracts.d.ts +3 -0
- package/dist/node/contracts.js +2 -0
- package/dist/node/contracts.js.map +1 -1
- package/dist/node/index.cjs +278 -5
- package/dist/node/marketplace/bb.d.ts +696 -0
- package/dist/node/marketplace/bb.js +276 -0
- package/dist/node/marketplace/bb.js.map +1 -0
- package/dist/node/marketplace/index.d.ts +1 -0
- package/dist/node/marketplace/index.js +1 -0
- package/dist/node/marketplace/index.js.map +1 -1
- package/dist/node/marketplace/offer.d.ts +1 -1
- package/dist/node/marketplace/offer.js +3 -3
- package/dist/node/marketplace/offer.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/tsconfig.web.tsbuildinfo +1 -1
- package/dist/web/contracts.d.ts +3 -0
- package/dist/web/contracts.js +2 -0
- package/dist/web/contracts.js.map +1 -1
- package/dist/web/marketplace/bb.d.ts +696 -0
- package/dist/web/marketplace/bb.js +276 -0
- package/dist/web/marketplace/bb.js.map +1 -0
- package/dist/web/marketplace/index.d.ts +1 -0
- package/dist/web/marketplace/index.js +1 -0
- package/dist/web/marketplace/index.js.map +1 -1
- package/dist/web/marketplace/offer.d.ts +1 -1
- package/dist/web/marketplace/offer.js +3 -3
- package/dist/web/marketplace/offer.js.map +1 -1
- package/package.json +7 -7
- package/src/contracts.ts +5 -0
- package/src/marketplace/bb.ts +288 -0
- package/src/marketplace/index.ts +1 -0
- package/src/marketplace/offer.ts +2 -2
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AccountUpdate,
|
|
3
|
+
DeployArgs,
|
|
4
|
+
method,
|
|
5
|
+
Permissions,
|
|
6
|
+
PublicKey,
|
|
7
|
+
State,
|
|
8
|
+
state,
|
|
9
|
+
UInt64,
|
|
10
|
+
SmartContract,
|
|
11
|
+
Bool,
|
|
12
|
+
Field,
|
|
13
|
+
Struct,
|
|
14
|
+
VerificationKey,
|
|
15
|
+
} from "o1js";
|
|
16
|
+
/**
|
|
17
|
+
* The BulletinBoard contract serves as a centralized event emitter for NFT marketplace activities.
|
|
18
|
+
* It provides a standardized way to broadcast and track various marketplace events such as:
|
|
19
|
+
* - New collection listings
|
|
20
|
+
* - Offers made on NFTs
|
|
21
|
+
* - Offer cancellations
|
|
22
|
+
* - Bids placed on NFTs
|
|
23
|
+
* - Bid cancellations
|
|
24
|
+
* - Completed sales
|
|
25
|
+
*
|
|
26
|
+
* While anyone can emit events through this contract, all events are prefixed with "BB_" to
|
|
27
|
+
* distinguish them from events emitted directly by NFT contracts. This helps maintain clarity
|
|
28
|
+
* in event tracking and marketplace activity monitoring.
|
|
29
|
+
*
|
|
30
|
+
* The BulletinBoard does not handle any NFT transfers or escrow - it purely exists as an
|
|
31
|
+
* event broadcasting mechanism to help indexers and UIs track marketplace activity.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
export {
|
|
35
|
+
BB_NewCollectionEvent,
|
|
36
|
+
BB_OfferEvent,
|
|
37
|
+
BB_CancelOfferEvent,
|
|
38
|
+
BB_BidEvent,
|
|
39
|
+
BB_CancelBidEvent,
|
|
40
|
+
BB_SaleEvent,
|
|
41
|
+
BB_UpgradeVerificationKeyEvent,
|
|
42
|
+
BB_ChangeAdminEvent,
|
|
43
|
+
BulletinBoard,
|
|
44
|
+
BulletinBoardDeployProps,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
class BB_NewCollectionEvent extends Struct({
|
|
48
|
+
/** The collection address. */
|
|
49
|
+
collection: PublicKey,
|
|
50
|
+
}) {}
|
|
51
|
+
|
|
52
|
+
class BB_OfferEvent extends Struct({
|
|
53
|
+
/** The collection address. */
|
|
54
|
+
collection: PublicKey,
|
|
55
|
+
/** The NFT address. */
|
|
56
|
+
nft: PublicKey,
|
|
57
|
+
/** The offer address. */
|
|
58
|
+
offer: PublicKey,
|
|
59
|
+
/** The price. */
|
|
60
|
+
price: UInt64,
|
|
61
|
+
}) {}
|
|
62
|
+
|
|
63
|
+
class BB_CancelOfferEvent extends Struct({
|
|
64
|
+
/** The collection address. */
|
|
65
|
+
collection: PublicKey,
|
|
66
|
+
/** The NFT address. */
|
|
67
|
+
nft: PublicKey,
|
|
68
|
+
}) {}
|
|
69
|
+
|
|
70
|
+
class BB_BidEvent extends Struct({
|
|
71
|
+
/** The collection address. */
|
|
72
|
+
collection: PublicKey,
|
|
73
|
+
/** The NFT address. */
|
|
74
|
+
nft: PublicKey,
|
|
75
|
+
/** The bid address. */
|
|
76
|
+
bid: PublicKey,
|
|
77
|
+
/** The price. */
|
|
78
|
+
price: UInt64,
|
|
79
|
+
}) {}
|
|
80
|
+
|
|
81
|
+
class BB_CancelBidEvent extends Struct({
|
|
82
|
+
/** The collection address. */
|
|
83
|
+
collection: PublicKey,
|
|
84
|
+
/** The NFT address. */
|
|
85
|
+
nft: PublicKey,
|
|
86
|
+
/** The bid address. */
|
|
87
|
+
bid: PublicKey,
|
|
88
|
+
}) {}
|
|
89
|
+
|
|
90
|
+
class BB_SaleEvent extends Struct({
|
|
91
|
+
/** The collection address. */
|
|
92
|
+
collection: PublicKey,
|
|
93
|
+
/** The NFT address. */
|
|
94
|
+
nft: PublicKey,
|
|
95
|
+
/** The buyer address. */
|
|
96
|
+
buyer: PublicKey,
|
|
97
|
+
/** The price. */
|
|
98
|
+
price: UInt64,
|
|
99
|
+
}) {}
|
|
100
|
+
|
|
101
|
+
class BB_UpgradeVerificationKeyEvent extends Struct({
|
|
102
|
+
/** The new verification key. */
|
|
103
|
+
vk: Field,
|
|
104
|
+
}) {}
|
|
105
|
+
|
|
106
|
+
class BB_ChangeAdminEvent extends Struct({
|
|
107
|
+
/** The new admin. */
|
|
108
|
+
admin: PublicKey,
|
|
109
|
+
}) {}
|
|
110
|
+
|
|
111
|
+
interface BulletinBoardDeployProps extends Exclude<DeployArgs, undefined> {
|
|
112
|
+
/** The admin. */
|
|
113
|
+
admin: PublicKey;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The BulletinBoard contract serves as a centralized event emitter for NFT marketplace activities.
|
|
117
|
+
* It provides a standardized way to broadcast and track various marketplace events such as:
|
|
118
|
+
* - New collection listings
|
|
119
|
+
* - Offers made on NFTs
|
|
120
|
+
* - Offer cancellations
|
|
121
|
+
* - Bids placed on NFTs
|
|
122
|
+
* - Bid cancellations
|
|
123
|
+
* - Completed sales
|
|
124
|
+
*
|
|
125
|
+
* While anyone can emit events through this contract, all events are prefixed with "BB_" to
|
|
126
|
+
* distinguish them from events emitted directly by NFT contracts. This helps maintain clarity
|
|
127
|
+
* in event tracking and marketplace activity monitoring.
|
|
128
|
+
*/
|
|
129
|
+
class BulletinBoard extends SmartContract {
|
|
130
|
+
@state(PublicKey) admin = State<PublicKey>();
|
|
131
|
+
|
|
132
|
+
async deploy(args: BulletinBoardDeployProps) {
|
|
133
|
+
await super.deploy(args);
|
|
134
|
+
this.admin.set(args.admin);
|
|
135
|
+
this.account.permissions.set({
|
|
136
|
+
...Permissions.default(),
|
|
137
|
+
send: Permissions.proof(),
|
|
138
|
+
setVerificationKey:
|
|
139
|
+
Permissions.VerificationKey.proofDuringCurrentVersion(),
|
|
140
|
+
setPermissions: Permissions.impossible(),
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
events = {
|
|
145
|
+
newCollection: BB_NewCollectionEvent,
|
|
146
|
+
offer: BB_OfferEvent,
|
|
147
|
+
cancelOffer: BB_CancelOfferEvent,
|
|
148
|
+
bid: BB_BidEvent,
|
|
149
|
+
cancelBid: BB_CancelBidEvent,
|
|
150
|
+
sale: BB_SaleEvent,
|
|
151
|
+
upgradeVerificationKey: BB_UpgradeVerificationKeyEvent,
|
|
152
|
+
changeAdmin: BB_ChangeAdminEvent,
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Emits a new collection event.
|
|
157
|
+
* @param collection - The collection address.
|
|
158
|
+
*/
|
|
159
|
+
@method async newCollection(collection: PublicKey) {
|
|
160
|
+
this.emitEvent(
|
|
161
|
+
"newCollection",
|
|
162
|
+
new BB_NewCollectionEvent({
|
|
163
|
+
collection,
|
|
164
|
+
})
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Emits an offer event.
|
|
170
|
+
* @param collection - The collection address.
|
|
171
|
+
* @param nft - The NFT address.
|
|
172
|
+
* @param offer - The offer address.
|
|
173
|
+
* @param price - The price.
|
|
174
|
+
*/
|
|
175
|
+
@method async offer(
|
|
176
|
+
collection: PublicKey,
|
|
177
|
+
nft: PublicKey,
|
|
178
|
+
offer: PublicKey,
|
|
179
|
+
price: UInt64
|
|
180
|
+
) {
|
|
181
|
+
this.emitEvent(
|
|
182
|
+
"offer",
|
|
183
|
+
new BB_OfferEvent({ collection, nft, offer, price })
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Emits a cancel offer event.
|
|
189
|
+
* @param collection - The collection address.
|
|
190
|
+
* @param nft - The NFT address.
|
|
191
|
+
*/
|
|
192
|
+
@method async cancelOffer(collection: PublicKey, nft: PublicKey) {
|
|
193
|
+
this.emitEvent("cancelOffer", new BB_CancelOfferEvent({ collection, nft }));
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Emits a bid event.
|
|
198
|
+
* @param collection - The collection address.
|
|
199
|
+
* @param nft - The NFT address.
|
|
200
|
+
* @param bid - The bid address.
|
|
201
|
+
* @param price - The price.
|
|
202
|
+
*/
|
|
203
|
+
@method async bid(
|
|
204
|
+
collection: PublicKey,
|
|
205
|
+
nft: PublicKey,
|
|
206
|
+
bid: PublicKey,
|
|
207
|
+
price: UInt64
|
|
208
|
+
) {
|
|
209
|
+
this.emitEvent("bid", new BB_BidEvent({ collection, nft, bid, price }));
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Emits a cancel bid event.
|
|
214
|
+
* @param collection - The collection address.
|
|
215
|
+
* @param nft - The NFT address.
|
|
216
|
+
* @param bid - The bid address.
|
|
217
|
+
*/
|
|
218
|
+
@method async cancelBid(
|
|
219
|
+
collection: PublicKey,
|
|
220
|
+
nft: PublicKey,
|
|
221
|
+
bid: PublicKey
|
|
222
|
+
) {
|
|
223
|
+
this.emitEvent(
|
|
224
|
+
"cancelBid",
|
|
225
|
+
new BB_CancelBidEvent({ collection, nft, bid })
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Emits a sale event.
|
|
231
|
+
* @param collection - The collection address.
|
|
232
|
+
* @param nft - The NFT address.
|
|
233
|
+
* @param buyer - The buyer address.
|
|
234
|
+
* @param price - The price.
|
|
235
|
+
*/
|
|
236
|
+
@method async sale(
|
|
237
|
+
collection: PublicKey,
|
|
238
|
+
nft: PublicKey,
|
|
239
|
+
buyer: PublicKey,
|
|
240
|
+
price: UInt64
|
|
241
|
+
) {
|
|
242
|
+
this.emitEvent("sale", new BB_SaleEvent({ collection, nft, buyer, price }));
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Ensures that the transaction is authorized by the contract owner.
|
|
247
|
+
* @returns A signed `AccountUpdate` from the admin.
|
|
248
|
+
*/
|
|
249
|
+
async ensureOwnerSignature(): Promise<AccountUpdate> {
|
|
250
|
+
const admin = this.admin.getAndRequireEquals();
|
|
251
|
+
const adminUpdate = AccountUpdate.createSigned(admin);
|
|
252
|
+
adminUpdate.body.useFullCommitment = Bool(true); // Prevent memo and fee change
|
|
253
|
+
return adminUpdate;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Changes the contract's admin
|
|
258
|
+
* @param admin - The new admin.
|
|
259
|
+
*/
|
|
260
|
+
@method
|
|
261
|
+
async changeAdmin(admin: PublicKey) {
|
|
262
|
+
await this.ensureOwnerSignature();
|
|
263
|
+
|
|
264
|
+
// Set the new admin
|
|
265
|
+
this.admin.set(admin);
|
|
266
|
+
|
|
267
|
+
// Emit the change admin event
|
|
268
|
+
this.emitEvent("changeAdmin", new BB_ChangeAdminEvent({ admin }));
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Upgrades the contract's verification key after validating with the upgrade authority.
|
|
273
|
+
* @param vk - The new verification key to upgrade to.
|
|
274
|
+
*/
|
|
275
|
+
@method
|
|
276
|
+
async upgradeVerificationKey(vk: VerificationKey) {
|
|
277
|
+
await this.ensureOwnerSignature();
|
|
278
|
+
|
|
279
|
+
// Set the new verification key
|
|
280
|
+
this.account.verificationKey.set(vk);
|
|
281
|
+
|
|
282
|
+
// Emit the upgrade event
|
|
283
|
+
this.emitEvent(
|
|
284
|
+
"upgradeVerificationKey",
|
|
285
|
+
new BB_UpgradeVerificationKeyEvent({ vk: vk.hash })
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
}
|
package/src/marketplace/index.ts
CHANGED
package/src/marketplace/offer.ts
CHANGED
|
@@ -84,7 +84,7 @@ export function OfferFactory(params: {
|
|
|
84
84
|
return new CollectionContract(address);
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
@method async buy() {
|
|
87
|
+
@method async buy(buyer: PublicKey) {
|
|
88
88
|
const insideBuy = this.insideBuy.getAndRequireEquals();
|
|
89
89
|
insideBuy.assertFalse("Already inside buy method");
|
|
90
90
|
this.insideBuy.set(Bool(true));
|
|
@@ -95,7 +95,7 @@ export function OfferFactory(params: {
|
|
|
95
95
|
await collection.transferByProof({
|
|
96
96
|
address: nftAddress,
|
|
97
97
|
from: this.address,
|
|
98
|
-
to:
|
|
98
|
+
to: buyer,
|
|
99
99
|
price: UInt64Option.fromValue(price),
|
|
100
100
|
context: new NFTTransactionContext({
|
|
101
101
|
custom: [Field(0), Field(0), Field(0)],
|