@bosonprotocol/core-sdk 1.33.1-alpha.2 → 1.34.0-alpha.0

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.
Files changed (82) hide show
  1. package/dist/cjs/accounts/handler.d.ts +27 -1
  2. package/dist/cjs/accounts/handler.d.ts.map +1 -1
  3. package/dist/cjs/accounts/handler.js +71 -2
  4. package/dist/cjs/accounts/handler.js.map +1 -1
  5. package/dist/cjs/accounts/interface.d.ts +15 -3
  6. package/dist/cjs/accounts/interface.d.ts.map +1 -1
  7. package/dist/cjs/accounts/interface.js +49 -6
  8. package/dist/cjs/accounts/interface.js.map +1 -1
  9. package/dist/cjs/accounts/mixin.d.ts +4 -0
  10. package/dist/cjs/accounts/mixin.d.ts.map +1 -1
  11. package/dist/cjs/accounts/mixin.js +19 -0
  12. package/dist/cjs/accounts/mixin.js.map +1 -1
  13. package/dist/cjs/accounts/subgraph.d.ts +2 -1
  14. package/dist/cjs/accounts/subgraph.d.ts.map +1 -1
  15. package/dist/cjs/accounts/subgraph.js +9 -1
  16. package/dist/cjs/accounts/subgraph.js.map +1 -1
  17. package/dist/cjs/accounts/types.d.ts +1 -1
  18. package/dist/cjs/accounts/types.d.ts.map +1 -1
  19. package/dist/cjs/accounts/types.js.map +1 -1
  20. package/dist/cjs/meta-tx/handler.d.ts.map +1 -1
  21. package/dist/cjs/meta-tx/handler.js +3 -1
  22. package/dist/cjs/meta-tx/handler.js.map +1 -1
  23. package/dist/cjs/orchestration/handler.d.ts.map +1 -1
  24. package/dist/cjs/orchestration/handler.js +9 -4
  25. package/dist/cjs/orchestration/handler.js.map +1 -1
  26. package/dist/cjs/orchestration/interface.d.ts +4 -4
  27. package/dist/cjs/orchestration/interface.d.ts.map +1 -1
  28. package/dist/cjs/orchestration/interface.js +8 -8
  29. package/dist/cjs/orchestration/interface.js.map +1 -1
  30. package/dist/cjs/subgraph.d.ts +3783 -1418
  31. package/dist/cjs/subgraph.d.ts.map +1 -1
  32. package/dist/cjs/subgraph.js +138 -38
  33. package/dist/cjs/subgraph.js.map +1 -1
  34. package/dist/cjs/utils/graphql.d.ts +13 -0
  35. package/dist/cjs/utils/graphql.d.ts.map +1 -1
  36. package/dist/esm/accounts/handler.d.ts +27 -1
  37. package/dist/esm/accounts/handler.d.ts.map +1 -1
  38. package/dist/esm/accounts/handler.js +59 -2
  39. package/dist/esm/accounts/handler.js.map +1 -1
  40. package/dist/esm/accounts/interface.d.ts +15 -3
  41. package/dist/esm/accounts/interface.d.ts.map +1 -1
  42. package/dist/esm/accounts/interface.js +42 -5
  43. package/dist/esm/accounts/interface.js.map +1 -1
  44. package/dist/esm/accounts/mixin.d.ts +4 -0
  45. package/dist/esm/accounts/mixin.d.ts.map +1 -1
  46. package/dist/esm/accounts/mixin.js +15 -0
  47. package/dist/esm/accounts/mixin.js.map +1 -1
  48. package/dist/esm/accounts/subgraph.d.ts +2 -1
  49. package/dist/esm/accounts/subgraph.d.ts.map +1 -1
  50. package/dist/esm/accounts/subgraph.js +5 -0
  51. package/dist/esm/accounts/subgraph.js.map +1 -1
  52. package/dist/esm/accounts/types.d.ts +1 -1
  53. package/dist/esm/accounts/types.d.ts.map +1 -1
  54. package/dist/esm/accounts/types.js.map +1 -1
  55. package/dist/esm/meta-tx/handler.d.ts.map +1 -1
  56. package/dist/esm/meta-tx/handler.js +7 -1
  57. package/dist/esm/meta-tx/handler.js.map +1 -1
  58. package/dist/esm/orchestration/handler.d.ts.map +1 -1
  59. package/dist/esm/orchestration/handler.js +9 -4
  60. package/dist/esm/orchestration/handler.js.map +1 -1
  61. package/dist/esm/orchestration/interface.d.ts +4 -4
  62. package/dist/esm/orchestration/interface.d.ts.map +1 -1
  63. package/dist/esm/orchestration/interface.js +8 -8
  64. package/dist/esm/orchestration/interface.js.map +1 -1
  65. package/dist/esm/subgraph.d.ts +3783 -1418
  66. package/dist/esm/subgraph.d.ts.map +1 -1
  67. package/dist/esm/subgraph.js +135 -35
  68. package/dist/esm/subgraph.js.map +1 -1
  69. package/dist/esm/utils/graphql.d.ts +13 -0
  70. package/dist/esm/utils/graphql.d.ts.map +1 -1
  71. package/package.json +3 -3
  72. package/src/accounts/handler.ts +93 -3
  73. package/src/accounts/interface.ts +78 -6
  74. package/src/accounts/mixin.ts +26 -0
  75. package/src/accounts/queries.graphql +61 -0
  76. package/src/accounts/subgraph.ts +14 -1
  77. package/src/accounts/types.ts +2 -1
  78. package/src/meta-tx/handler.ts +7 -1
  79. package/src/offers/queries.graphql +3 -0
  80. package/src/orchestration/handler.ts +13 -1
  81. package/src/orchestration/interface.ts +8 -4
  82. package/src/subgraph.ts +2964 -499
@@ -15,16 +15,21 @@ import {
15
15
  OptInToSellerUpdateArgs,
16
16
  SellerUpdateFields,
17
17
  OptInToDisputeResolverUpdateArgs,
18
- DisputeResolverUpdateFields
18
+ DisputeResolverUpdateFields,
19
+ CreateCollectionArgs
19
20
  } from "./types";
20
21
  import { AddressZero } from "@ethersproject/constants";
22
+ import { INITIAL_COLLECTION_ID } from "./handler";
21
23
 
22
24
  export const bosonAccountHandlerIface = new Interface(
23
25
  abis.IBosonAccountHandlerABI
24
26
  );
25
27
 
26
- export function encodeCreateSeller(seller: CreateSellerArgs) {
27
- const sellerArgs = createSellerArgsToStruct(seller);
28
+ export function encodeCreateSeller(
29
+ seller: CreateSellerArgs,
30
+ collectionSalt: string
31
+ ) {
32
+ const sellerArgs = createSellerArgsToStruct(seller, collectionSalt);
28
33
  return bosonAccountHandlerIface.encodeFunctionData("createSeller", [
29
34
  sellerArgs.sellerStruct,
30
35
  sellerArgs.authTokenStruct,
@@ -32,6 +37,14 @@ export function encodeCreateSeller(seller: CreateSellerArgs) {
32
37
  ]);
33
38
  }
34
39
 
40
+ export function encodeCreateNewCollection(collection: CreateCollectionArgs) {
41
+ const collectionArgs = createCollectionArgsToStruct(collection);
42
+ return bosonAccountHandlerIface.encodeFunctionData("createNewCollection", [
43
+ collectionArgs.externalId,
44
+ collectionArgs.voucherInitValues
45
+ ]);
46
+ }
47
+
35
48
  export function encodeUpdateSeller(seller: UpdateSellerArgs) {
36
49
  const sellerArgs = updateSellerArgsToStruct(seller);
37
50
  return bosonAccountHandlerIface.encodeFunctionData("updateSeller", [
@@ -129,7 +142,10 @@ export function encodeOptInToDisputeResolverUpdate(
129
142
  }
130
143
 
131
144
  // TODO: add a unit test for collectionId
132
- export function createSellerArgsToStruct(args: CreateSellerArgs): {
145
+ export function createSellerArgsToStruct(
146
+ args: CreateSellerArgs,
147
+ collectionSalt: string
148
+ ): {
133
149
  sellerStruct: Partial<SellerStruct>;
134
150
  authTokenStruct: AuthTokenStruct;
135
151
  voucherInitValues: VoucherInitValuesStruct;
@@ -139,10 +155,8 @@ export function createSellerArgsToStruct(args: CreateSellerArgs): {
139
155
  authTokenType,
140
156
  contractUri,
141
157
  royaltyPercentage,
142
- collectionId,
143
158
  ...sellerStructArgs
144
159
  } = args;
145
- const collectionSalt = formatBytes32String(collectionId || "collection-0");
146
160
  return {
147
161
  sellerStruct: argsToSellerStruct(sellerStructArgs),
148
162
  authTokenStruct: {
@@ -157,6 +171,24 @@ export function createSellerArgsToStruct(args: CreateSellerArgs): {
157
171
  };
158
172
  }
159
173
 
174
+ export function createCollectionArgsToStruct(args: CreateCollectionArgs): {
175
+ externalId: string;
176
+ voucherInitValues: VoucherInitValuesStruct;
177
+ } {
178
+ const { collectionId, contractUri, royaltyPercentage } = args;
179
+ const collectionSalt =
180
+ args.collectionSalt ||
181
+ formatBytes32String(collectionId || INITIAL_COLLECTION_ID);
182
+ return {
183
+ externalId: collectionId,
184
+ voucherInitValues: {
185
+ contractURI: contractUri,
186
+ royaltyPercentage,
187
+ collectionSalt
188
+ }
189
+ };
190
+ }
191
+
160
192
  export function updateSellerArgsToStruct(args: UpdateSellerArgs) {
161
193
  const { authTokenId, authTokenType, ...sellerStructArgs } = args;
162
194
  return {
@@ -201,3 +233,43 @@ function createDisputeResolverArgsToDisputeResolverStruct(
201
233
  )
202
234
  };
203
235
  }
236
+
237
+ export function encodeIsSellerSaltAvailable(
238
+ adminAddress: string,
239
+ salt: string
240
+ ) {
241
+ return bosonAccountHandlerIface.encodeFunctionData("isSellerSaltAvailable", [
242
+ adminAddress,
243
+ salt
244
+ ]);
245
+ }
246
+
247
+ export function decodeIsSellerSaltAvailable(result: string): boolean {
248
+ const [isAvailable] = bosonAccountHandlerIface.decodeFunctionResult(
249
+ "isSellerSaltAvailable",
250
+ result
251
+ );
252
+ return isAvailable;
253
+ }
254
+
255
+ export function encodeCalculateCollectionAddress(
256
+ sellerId: BigNumberish,
257
+ collectionSalt: string
258
+ ) {
259
+ return bosonAccountHandlerIface.encodeFunctionData(
260
+ "calculateCollectionAddress",
261
+ [sellerId, collectionSalt]
262
+ );
263
+ }
264
+
265
+ export function decodeCalculateCollectionAddress(result: string): {
266
+ collectionAddress: string;
267
+ isAvailable: boolean;
268
+ } {
269
+ const [collectionAddress, isAvailable] =
270
+ bosonAccountHandlerIface.decodeFunctionResult(
271
+ "calculateCollectionAddress",
272
+ result
273
+ );
274
+ return { collectionAddress, isAvailable };
275
+ }
@@ -588,4 +588,30 @@ export class AccountsMixin extends BaseCoreSDK {
588
588
  ): Promise<subgraph.DisputeResolverFieldsFragment[]> {
589
589
  return accounts.subgraph.getDisputeResolvers(this._subgraphUrl, queryVars);
590
590
  }
591
+
592
+ public async createNewCollection(
593
+ collectionToCreate: accounts.CreateCollectionArgs,
594
+ overrides: Partial<{
595
+ contractAddress: string;
596
+ }> = {}
597
+ ): Promise<TransactionResponse> {
598
+ if (!collectionToCreate.sellerId) {
599
+ const { id: sellerId } = await this.getSellerByAssistant(
600
+ await this._web3Lib.getSignerAddress()
601
+ );
602
+ // If the caller is not a seller, the sellerId remains undefined
603
+ collectionToCreate.sellerId = sellerId;
604
+ }
605
+ return accounts.handler.createNewCollection({
606
+ collectionToCreate,
607
+ web3Lib: this._web3Lib,
608
+ contractAddress: overrides.contractAddress || this._protocolDiamond
609
+ });
610
+ }
611
+
612
+ public async getOfferCollections(
613
+ queryVars?: subgraph.GetOfferCollectionsQueryQueryVariables
614
+ ): Promise<subgraph.OfferCollectionFieldsFragment[]> {
615
+ return accounts.subgraph.getOfferCollections(this._subgraphUrl, queryVars);
616
+ }
591
617
  }
@@ -208,8 +208,69 @@ query getConditionalCommitAuthorizedEventLogsQuery(
208
208
  }
209
209
  }
210
210
 
211
+ query getOfferCollectionsQuery(
212
+ $offerCollectionsSkip: Int
213
+ $offerCollectionsFirst: Int
214
+ $offerCollectionsOrderBy: OfferCollection_orderBy
215
+ $offerCollectionsOrderDirection: OrderDirection
216
+ $offerCollectionsFilter: OfferCollection_filter
217
+ $offersSkip: Int
218
+ $offersFirst: Int
219
+ $offersOrderBy: Offer_orderBy
220
+ $offersOrderDirection: OrderDirection
221
+ $offersFilter: Offer_filter
222
+ $includeOffers: Boolean = false
223
+ ) {
224
+ offerCollections(
225
+ skip: $offerCollectionsSkip
226
+ first: $offerCollectionsFirst
227
+ orderBy: $offerCollectionsOrderBy
228
+ orderDirection: $offerCollectionsOrderDirection
229
+ where: $offerCollectionsFilter
230
+ ) {
231
+ ...OfferCollectionFields
232
+ }
233
+ }
234
+
235
+ fragment OfferCollectionFields on OfferCollection {
236
+ ...BaseOfferCollectionFields
237
+ seller {
238
+ ...BaseSellerFields
239
+ }
240
+ offers(
241
+ skip: $offersSkip
242
+ first: $offersFirst
243
+ orderBy: $offersOrderBy
244
+ orderDirection: $offersOrderDirection
245
+ where: $offersFilter
246
+ ) @include(if: $includeOffers) {
247
+ ...BaseOfferFields
248
+ }
249
+ }
250
+
251
+ fragment BaseOfferCollectionFields on OfferCollection {
252
+ id
253
+ sellerId
254
+ collectionIndex
255
+ collectionAddress
256
+ externalIdHash
257
+ externalId
258
+ metadata {
259
+ id
260
+ name
261
+ description
262
+ image
263
+ externalLink
264
+ createdAt
265
+ collaborators
266
+ }
267
+ }
268
+
211
269
  fragment SellerFields on Seller {
212
270
  ...BaseSellerFields
271
+ collections {
272
+ ...BaseOfferCollectionFields
273
+ }
213
274
  pendingSeller {
214
275
  ...PendingSellerFields
215
276
  }
@@ -8,7 +8,9 @@ import {
8
8
  GetSellerByIdQueryQueryVariables,
9
9
  GetDisputeResolverByIdQueryQueryVariables,
10
10
  GetDisputeResolversQueryQueryVariables,
11
- DisputeResolverFieldsFragment
11
+ DisputeResolverFieldsFragment,
12
+ GetOfferCollectionsQueryQueryVariables,
13
+ OfferCollectionFieldsFragment
12
14
  } from "../subgraph";
13
15
  import { BigNumberish } from "@ethersproject/bignumber";
14
16
 
@@ -169,3 +171,14 @@ export async function getDisputeResolvers(
169
171
  );
170
172
  return disputeResolvers;
171
173
  }
174
+
175
+ export async function getOfferCollections(
176
+ subgraphUrl: string,
177
+ queryVars: GetOfferCollectionsQueryQueryVariables = {}
178
+ ): Promise<OfferCollectionFieldsFragment[]> {
179
+ const sdk = getSubgraphSdk(subgraphUrl);
180
+ const { offerCollections = [] } = await sdk.getOfferCollectionsQuery(
181
+ queryVars
182
+ );
183
+ return offerCollections;
184
+ }
@@ -13,7 +13,8 @@ export {
13
13
  OptInToSellerUpdateArgs,
14
14
  DisputeResolverUpdateFields,
15
15
  OptInToDisputeResolverUpdateArgs,
16
- utils
16
+ utils,
17
+ CreateCollectionArgs
17
18
  } from "@bosonprotocol/common";
18
19
 
19
20
  export type CreateDisputeResolverArgs = {
@@ -54,6 +54,7 @@ import { ERC20ForwardRequest } from "../forwarder/biconomy-interface";
54
54
  import { getNonce, verifyEIP712 } from "../forwarder/handler";
55
55
  import { MockForwardRequest } from "../forwarder/mock-interface";
56
56
  import { isTrustedForwarder } from "../voucher/handler";
57
+ import { findCollectionSalt } from "../accounts/handler";
57
58
 
58
59
  export type BaseMetaTxArgs = {
59
60
  web3Lib: Web3LibAdapter;
@@ -395,11 +396,16 @@ export async function signMetaTxCreateSeller(
395
396
  metadataStorage: args.metadataStorage,
396
397
  theGraphStorage: args.theGraphStorage
397
398
  });
399
+ const collectionSalt = await findCollectionSalt({
400
+ sellerToCreate: args.createSellerArgs,
401
+ contractAddress: args.metaTxHandlerAddress,
402
+ ...args
403
+ });
398
404
  return signMetaTx({
399
405
  ...args,
400
406
  functionName:
401
407
  "createSeller((uint256,address,address,address,address,bool,string),(uint256,uint8),(string,uint256,bytes32))",
402
- functionSignature: encodeCreateSeller(args.createSellerArgs)
408
+ functionSignature: encodeCreateSeller(args.createSellerArgs, collectionSalt)
403
409
  });
404
410
  }
405
411
 
@@ -133,6 +133,9 @@ fragment BaseOfferFields on Offer {
133
133
  seller {
134
134
  ...BaseSellerFields
135
135
  }
136
+ collection {
137
+ ...BaseOfferCollectionFields
138
+ }
136
139
  exchangeToken {
137
140
  ...BaseExchangeTokenFields
138
141
  }
@@ -20,6 +20,7 @@ import { storeMetadataOnTheGraph } from "../offers/storage";
20
20
  import { CreateOfferArgs } from "../offers/types";
21
21
  import { CreateSellerArgs } from "../accounts/types";
22
22
  import { BigNumberish } from "@ethersproject/bignumber";
23
+ import { findCollectionSalt } from "../accounts/handler";
23
24
 
24
25
  export async function createOfferAndSeller(args: {
25
26
  offerToCreate: CreateOfferArgs;
@@ -48,9 +49,14 @@ export async function createOfferAndSeller(args: {
48
49
  )
49
50
  );
50
51
 
52
+ const collectionSalt = await findCollectionSalt(args);
51
53
  return args.web3Lib.sendTransaction({
52
54
  to: args.contractAddress,
53
- data: encodeCreateSellerAndOffer(args.sellerToCreate, args.offerToCreate)
55
+ data: encodeCreateSellerAndOffer(
56
+ args.sellerToCreate,
57
+ collectionSalt,
58
+ args.offerToCreate
59
+ )
54
60
  });
55
61
  }
56
62
 
@@ -102,10 +108,12 @@ export async function createSellerAndOfferWithCondition(args: {
102
108
  )
103
109
  );
104
110
 
111
+ const collectionSalt = await findCollectionSalt(args);
105
112
  return args.web3Lib.sendTransaction({
106
113
  to: args.contractAddress,
107
114
  data: encodeCreateSellerAndOfferWithCondition(
108
115
  args.sellerToCreate,
116
+ collectionSalt,
109
117
  args.offerToCreate,
110
118
  args.condition
111
119
  )
@@ -194,10 +202,12 @@ export async function createSellerAndPremintedOffer(args: {
194
202
  )
195
203
  );
196
204
 
205
+ const collectionSalt = await findCollectionSalt(args);
197
206
  return args.web3Lib.sendTransaction({
198
207
  to: args.contractAddress,
199
208
  data: encodeCreateSellerAndPremintedOffer(
200
209
  args.sellerToCreate,
210
+ collectionSalt,
201
211
  args.offerToCreate,
202
212
  args.reservedRangeLength
203
213
  )
@@ -229,10 +239,12 @@ export async function createSellerAndPremintedOfferWithCondition(args: {
229
239
  )
230
240
  );
231
241
 
242
+ const collectionSalt = await findCollectionSalt(args);
232
243
  return args.web3Lib.sendTransaction({
233
244
  to: args.contractAddress,
234
245
  data: encodeCreateSellerAndPremintedOfferWithCondition(
235
246
  args.sellerToCreate,
247
+ collectionSalt,
236
248
  args.offerToCreate,
237
249
  args.reservedRangeLength,
238
250
  args.condition
@@ -14,9 +14,10 @@ export const bosonOrchestrationHandlerIface = new Interface(
14
14
 
15
15
  export function encodeCreateSellerAndOffer(
16
16
  seller: CreateSellerArgs,
17
+ collectionSalt: string,
17
18
  offer: CreateOfferArgs
18
19
  ) {
19
- const sellerArgs = createSellerArgsToStruct(seller);
20
+ const sellerArgs = createSellerArgsToStruct(seller, collectionSalt);
20
21
  const offerArgs = createOfferArgsToStructs(offer);
21
22
  return bosonOrchestrationHandlerIface.encodeFunctionData(
22
23
  "createSellerAndOffer",
@@ -53,10 +54,11 @@ export function encodeCreateOfferWithCondition(
53
54
 
54
55
  export function encodeCreateSellerAndOfferWithCondition(
55
56
  seller: CreateSellerArgs,
57
+ collectionSalt: string,
56
58
  offer: CreateOfferArgs,
57
59
  condition: ConditionStruct
58
60
  ) {
59
- const sellerArgs = createSellerArgsToStruct(seller);
61
+ const sellerArgs = createSellerArgsToStruct(seller, collectionSalt);
60
62
  const offerArgs = createOfferArgsToStructs(offer);
61
63
  return bosonOrchestrationHandlerIface.encodeFunctionData(
62
64
  "createSellerAndOfferWithCondition",
@@ -117,10 +119,11 @@ export function encodeCreatePremintedOfferWithCondition(
117
119
 
118
120
  export function encodeCreateSellerAndPremintedOffer(
119
121
  seller: CreateSellerArgs,
122
+ collectionSalt: string,
120
123
  offer: CreateOfferArgs,
121
124
  reservedRangeLength: BigNumberish
122
125
  ) {
123
- const sellerArgs = createSellerArgsToStruct(seller);
126
+ const sellerArgs = createSellerArgsToStruct(seller, collectionSalt);
124
127
  const offerArgs = createOfferArgsToStructs(offer);
125
128
  return bosonOrchestrationHandlerIface.encodeFunctionData(
126
129
  "createSellerAndPremintedOffer",
@@ -140,11 +143,12 @@ export function encodeCreateSellerAndPremintedOffer(
140
143
 
141
144
  export function encodeCreateSellerAndPremintedOfferWithCondition(
142
145
  seller: CreateSellerArgs,
146
+ collectionSalt: string,
143
147
  offer: CreateOfferArgs,
144
148
  reservedRangeLength: BigNumberish,
145
149
  condition: ConditionStruct
146
150
  ) {
147
- const sellerArgs = createSellerArgsToStruct(seller);
151
+ const sellerArgs = createSellerArgsToStruct(seller, collectionSalt);
148
152
  const offerArgs = createOfferArgsToStructs(offer);
149
153
  return bosonOrchestrationHandlerIface.encodeFunctionData(
150
154
  "createSellerAndPremintedOfferWithCondition",