@bosonprotocol/core-sdk 1.11.0-alpha.0 → 1.11.0-alpha.10

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 (73) hide show
  1. package/dist/cjs/accounts/subgraph.d.ts +5 -1
  2. package/dist/cjs/accounts/subgraph.d.ts.map +1 -1
  3. package/dist/cjs/accounts/subgraph.js +28 -4
  4. package/dist/cjs/accounts/subgraph.js.map +1 -1
  5. package/dist/cjs/core-sdk.d.ts +240 -4
  6. package/dist/cjs/core-sdk.d.ts.map +1 -1
  7. package/dist/cjs/core-sdk.js +295 -19
  8. package/dist/cjs/core-sdk.js.map +1 -1
  9. package/dist/cjs/erc20/index.d.ts +1 -0
  10. package/dist/cjs/erc20/index.d.ts.map +1 -1
  11. package/dist/cjs/erc20/index.js +2 -1
  12. package/dist/cjs/erc20/index.js.map +1 -1
  13. package/dist/cjs/erc20/subgraph.d.ts +5 -0
  14. package/dist/cjs/erc20/subgraph.d.ts.map +1 -0
  15. package/dist/cjs/erc20/subgraph.js +30 -0
  16. package/dist/cjs/erc20/subgraph.js.map +1 -0
  17. package/dist/cjs/metadata/index.d.ts +2 -0
  18. package/dist/cjs/metadata/index.d.ts.map +1 -0
  19. package/dist/cjs/metadata/index.js +28 -0
  20. package/dist/cjs/metadata/index.js.map +1 -0
  21. package/dist/cjs/metadata/subgraph.d.ts +11 -0
  22. package/dist/cjs/metadata/subgraph.d.ts.map +1 -0
  23. package/dist/cjs/metadata/subgraph.js +62 -0
  24. package/dist/cjs/metadata/subgraph.js.map +1 -0
  25. package/dist/cjs/subgraph.d.ts +1996 -174
  26. package/dist/cjs/subgraph.d.ts.map +1 -1
  27. package/dist/cjs/subgraph.js +535 -13
  28. package/dist/cjs/subgraph.js.map +1 -1
  29. package/dist/cjs/utils/graphql.d.ts +83 -0
  30. package/dist/cjs/utils/graphql.d.ts.map +1 -1
  31. package/dist/esm/accounts/subgraph.d.ts +5 -1
  32. package/dist/esm/accounts/subgraph.d.ts.map +1 -1
  33. package/dist/esm/accounts/subgraph.js +27 -3
  34. package/dist/esm/accounts/subgraph.js.map +1 -1
  35. package/dist/esm/core-sdk.d.ts +240 -4
  36. package/dist/esm/core-sdk.d.ts.map +1 -1
  37. package/dist/esm/core-sdk.js +285 -17
  38. package/dist/esm/core-sdk.js.map +1 -1
  39. package/dist/esm/erc20/index.d.ts +1 -0
  40. package/dist/esm/erc20/index.d.ts.map +1 -1
  41. package/dist/esm/erc20/index.js +1 -0
  42. package/dist/esm/erc20/index.js.map +1 -1
  43. package/dist/esm/erc20/subgraph.d.ts +5 -0
  44. package/dist/esm/erc20/subgraph.d.ts.map +1 -0
  45. package/dist/esm/erc20/subgraph.js +15 -0
  46. package/dist/esm/erc20/subgraph.js.map +1 -0
  47. package/dist/esm/metadata/index.d.ts +2 -0
  48. package/dist/esm/metadata/index.d.ts.map +1 -0
  49. package/dist/esm/metadata/index.js +2 -0
  50. package/dist/esm/metadata/index.js.map +1 -0
  51. package/dist/esm/metadata/subgraph.d.ts +11 -0
  52. package/dist/esm/metadata/subgraph.d.ts.map +1 -0
  53. package/dist/esm/metadata/subgraph.js +46 -0
  54. package/dist/esm/metadata/subgraph.js.map +1 -0
  55. package/dist/esm/subgraph.d.ts +1996 -174
  56. package/dist/esm/subgraph.d.ts.map +1 -1
  57. package/dist/esm/subgraph.js +533 -11
  58. package/dist/esm/subgraph.js.map +1 -1
  59. package/dist/esm/utils/graphql.d.ts +83 -0
  60. package/dist/esm/utils/graphql.d.ts.map +1 -1
  61. package/package.json +4 -3
  62. package/src/accounts/subgraph.ts +49 -3
  63. package/src/core-sdk.ts +323 -23
  64. package/src/erc20/index.ts +1 -0
  65. package/src/erc20/queries.graphql +84 -0
  66. package/src/erc20/subgraph.ts +33 -0
  67. package/src/funds/queries.graphql +7 -6
  68. package/src/metadata/base.graphql +63 -0
  69. package/src/metadata/index.ts +1 -0
  70. package/src/metadata/product-v1.graphql +285 -0
  71. package/src/metadata/subgraph.ts +105 -0
  72. package/src/offers/queries.graphql +1 -4
  73. package/src/subgraph.ts +2646 -197
package/src/core-sdk.ts CHANGED
@@ -16,6 +16,7 @@ import * as orchestration from "./orchestration";
16
16
  import * as erc20 from "./erc20";
17
17
  import * as funds from "./funds";
18
18
  import * as metaTx from "./meta-tx";
19
+ import * as metadata from "./metadata";
19
20
  import * as subgraph from "./subgraph";
20
21
 
21
22
  import { getValueFromLogs } from "./utils/logs";
@@ -28,6 +29,10 @@ export class CoreSDK {
28
29
  private _subgraphUrl: string;
29
30
  private _protocolDiamond: string;
30
31
 
32
+ /**
33
+ * Creates an instance of `CoreSDK`
34
+ * @param args - Constructor args
35
+ */
31
36
  constructor(opts: {
32
37
  web3Lib: Web3LibAdapter;
33
38
  subgraphUrl: string;
@@ -42,6 +47,22 @@ export class CoreSDK {
42
47
  this._theGraphStorage = opts.theGraphStorage;
43
48
  }
44
49
 
50
+ /**
51
+ * Creates an instance of `CoreSDK` by using default values derived either from
52
+ * `args.envName` or `args.chainId`.
53
+ *
54
+ * @example
55
+ * Instance which uses the default contract address and subgraph url of mainnet:
56
+ * ```ts
57
+ * const coreSdk = CoreSDK.fromDefaultConfig({
58
+ * ...otherArgs,
59
+ * chainId: 137
60
+ * })
61
+ * ```
62
+ *
63
+ * @param args - Constructor args.
64
+ * @returns CoreSDK instance with default values.
65
+ */
45
66
  static fromDefaultConfig(args: {
46
67
  web3Lib: Web3LibAdapter;
47
68
  envName?: string;
@@ -63,6 +84,16 @@ export class CoreSDK {
63
84
  });
64
85
  }
65
86
 
87
+ /* -------------------------------------------------------------------------- */
88
+ /* Metadata related methods */
89
+ /* -------------------------------------------------------------------------- */
90
+
91
+ /**
92
+ * Stores supported offer metadata via the MetadataStorage instance which was passed in
93
+ * at construction.
94
+ * @param metadata - Offer metadata of type `BASE` or `PRODUCT_V1`.
95
+ * @returns Metadata hash / identifier.
96
+ */
66
97
  public async storeMetadata(metadata: AnyMetadata): Promise<string> {
67
98
  if (!this._metadataStorage) {
68
99
  throw new Error("No metadata storage set");
@@ -71,6 +102,12 @@ export class CoreSDK {
71
102
  return this._metadataStorage.storeMetadata(metadata);
72
103
  }
73
104
 
105
+ /**
106
+ * Returns supported offer metadata from passed in `MetadataStorage` instance.
107
+ * @param metadataHashOrUri - Metadata hash or uri that can be handled by the
108
+ * storage instance.
109
+ * @returns Metadata hash / identifier.
110
+ */
74
111
  public async getMetadata(metadataHashOrUri: string): Promise<AnyMetadata> {
75
112
  if (!this._metadataStorage) {
76
113
  throw new Error("No metadata storage set");
@@ -79,6 +116,46 @@ export class CoreSDK {
79
116
  return this._metadataStorage.getMetadata(metadataHashOrUri);
80
117
  }
81
118
 
119
+ /**
120
+ * Returns `BASE` type offer metadata entities from subgraph.
121
+ * @param queryVars - Optional query variables to skip, order or filter.
122
+ * @returns BaseMetadataEntities from subgraph.
123
+ */
124
+ public async getBaseMetadataEntities(
125
+ queryVars?: subgraph.GetBaseMetadataEntitiesQueryQueryVariables
126
+ ): Promise<subgraph.BaseMetadataEntityFieldsFragment[]> {
127
+ return metadata.subgraph.getBaseMetadataEntities(
128
+ this._subgraphUrl,
129
+ queryVars
130
+ );
131
+ }
132
+
133
+ /**
134
+ * Returns `PRODUCT_V1` type offer metadata entities from subgraph.
135
+ * @param queryVars - Optional query variables to skip, order or filter.
136
+ * @returns ProductV1MetadataEntities from subgraph.
137
+ */
138
+ public async getProductV1MetadataEntities(
139
+ queryVars?: subgraph.GetProductV1MetadataEntitiesQueryQueryVariables
140
+ ): Promise<subgraph.ProductV1MetadataEntityFieldsFragment[]> {
141
+ return metadata.subgraph.getProductV1MetadataEntities(
142
+ this._subgraphUrl,
143
+ queryVars
144
+ );
145
+ }
146
+
147
+ /* -------------------------------------------------------------------------- */
148
+ /* Account related methods */
149
+ /* -------------------------------------------------------------------------- */
150
+
151
+ /* --------------------------------- Seller --------------------------------- */
152
+
153
+ /**
154
+ * Returns seller entity from subgraph.
155
+ * @param sellerId - ID of seller entity to query for.
156
+ * @param queryVars - Optional query variables to skip, order or filter.
157
+ * @returns Seller entity from subgraph.
158
+ */
82
159
  public async getSellerById(
83
160
  sellerId: BigNumberish,
84
161
  queryVars?: accounts.subgraph.SingleSellerQueryVariables
@@ -90,6 +167,12 @@ export class CoreSDK {
90
167
  );
91
168
  }
92
169
 
170
+ /**
171
+ * Returns seller entity from subgraph.
172
+ * @param operator - Operator address of seller entity to query for.
173
+ * @param queryVars - Optional query variables to skip, order or filter.
174
+ * @returns Seller entity from subgraph.
175
+ */
93
176
  public async getSellerByOperator(
94
177
  operator: string,
95
178
  queryVars?: subgraph.GetSellersQueryQueryVariables
@@ -101,6 +184,12 @@ export class CoreSDK {
101
184
  );
102
185
  }
103
186
 
187
+ /**
188
+ * Returns seller entity from subgraph.
189
+ * @param clerk - Clerk address of seller entity to query for.
190
+ * @param queryVars - Optional query variables to skip, order or filter.
191
+ * @returns Seller entity from subgraph.
192
+ */
104
193
  public async getSellerByClerk(
105
194
  clerk: string,
106
195
  queryVars?: subgraph.GetSellersQueryQueryVariables
@@ -112,6 +201,12 @@ export class CoreSDK {
112
201
  );
113
202
  }
114
203
 
204
+ /**
205
+ * Returns seller entity from subgraph. Matches `operator`, `clerk`, `admin` or `treasury`.
206
+ * @param address - Address of seller entity to query for.
207
+ * @param queryVars - Optional query variables to skip, order or filter.
208
+ * @returns Seller entity from subgraph.
209
+ */
115
210
  public async getSellerByAddress(
116
211
  address: string,
117
212
  queryVars?: subgraph.GetSellersQueryQueryVariables
@@ -123,12 +218,23 @@ export class CoreSDK {
123
218
  );
124
219
  }
125
220
 
221
+ /**
222
+ * Returns seller entities from subgraph.
223
+ * @param queryVars - Optional query variables to skip, order or filter.
224
+ * @returns Seller entities from subgraph.
225
+ */
126
226
  public async getSellers(
127
227
  queryVars?: subgraph.GetSellersQueryQueryVariables
128
228
  ): Promise<subgraph.SellerFieldsFragment[]> {
129
229
  return accounts.subgraph.getSellers(this._subgraphUrl, queryVars);
130
230
  }
131
231
 
232
+ /**
233
+ * Creates seller account by calling the `AccountHandlerFacet` contract.
234
+ * @param sellerToCreate - Addresses to set in the seller account.
235
+ * @param overrides - Optional overrides.
236
+ * @returns Transaction response.
237
+ */
132
238
  public async createSeller(
133
239
  sellerToCreate: accounts.CreateSellerArgs,
134
240
  overrides: Partial<{
@@ -142,6 +248,14 @@ export class CoreSDK {
142
248
  });
143
249
  }
144
250
 
251
+ /**
252
+ * Creates seller account and offer by calling the `OrchestrationHandlerFacet` contract.
253
+ * This transaction only succeeds if there is no existing seller account for the connected signer.
254
+ * @param sellerToCreate - Addresses to set in the seller account.
255
+ * @param offerToCreate - Offer arguments.
256
+ * @param overrides - Optional overrides.
257
+ * @returns Transaction response.
258
+ */
145
259
  public async createSellerAndOffer(
146
260
  sellerToCreate: accounts.CreateSellerArgs,
147
261
  offerToCreate: offers.CreateOfferArgs,
@@ -159,6 +273,47 @@ export class CoreSDK {
159
273
  });
160
274
  }
161
275
 
276
+ /* ---------------------------------- Buyer --------------------------------- */
277
+
278
+ /**
279
+ * Returns buyer entity from subgraph.
280
+ * @param buyerId - ID of buyer entity to query for.
281
+ * @param queryVars - Optional query variables to skip, order or filter.
282
+ * @returns Buyer entity from subgraph.
283
+ */
284
+ public async getBuyerById(
285
+ buyerId: BigNumberish,
286
+ queryVars?: accounts.subgraph.SingleBuyerQueryVariables
287
+ ): Promise<subgraph.BuyerFieldsFragment> {
288
+ return accounts.subgraph.getBuyerById(
289
+ this._subgraphUrl,
290
+ buyerId,
291
+ queryVars
292
+ );
293
+ }
294
+
295
+ /**
296
+ * Returns buyer entities from subgraph.
297
+ * @param queryVars - Optional query variables to skip, order or filter.
298
+ * @returns Seller entities from subgraph.
299
+ */
300
+ public async getBuyers(
301
+ queryVars?: subgraph.GetBuyersQueryQueryVariables
302
+ ): Promise<subgraph.BuyerFieldsFragment[]> {
303
+ return accounts.subgraph.getBuyers(this._subgraphUrl, queryVars);
304
+ }
305
+
306
+ /* -------------------------------------------------------------------------- */
307
+ /* Offer related methods */
308
+ /* -------------------------------------------------------------------------- */
309
+
310
+ /**
311
+ * Creates offer by calling the `OfferHandlerFacet` contract.
312
+ * This transaction only succeeds if there is an existing seller account for connected signer.
313
+ * @param offerToCreate - Offer arguments.
314
+ * @param overrides - Optional overrides.
315
+ * @returns Transaction response.
316
+ */
162
317
  public async createOffer(
163
318
  offerToCreate: offers.CreateOfferArgs,
164
319
  overrides: Partial<{
@@ -174,6 +329,12 @@ export class CoreSDK {
174
329
  });
175
330
  }
176
331
 
332
+ /**
333
+ * Utility method to retrieve the created `offerId` from logs after calling `createOffer`
334
+ * or `createOfferAndSeller`.
335
+ * @param logs - Logs to search in.
336
+ * @returns Created offer id.
337
+ */
177
338
  public getCreatedOfferIdFromLogs(logs: Log[]): string | null {
178
339
  const offerId = getValueFromLogs({
179
340
  iface: offers.iface.bosonOfferHandlerIface,
@@ -193,6 +354,13 @@ export class CoreSDK {
193
354
  );
194
355
  }
195
356
 
357
+ /**
358
+ * Voids an existing offer by calling the `OfferHandlerFacet` contract.
359
+ * This transaction only succeeds if the connected signer is the `operator`.
360
+ * @param offerId - ID of offer to void.
361
+ * @param overrides - Optional overrides.
362
+ * @returns Transaction response.
363
+ */
196
364
  public async voidOffer(
197
365
  offerId: BigNumberish,
198
366
  overrides: Partial<{
@@ -207,6 +375,12 @@ export class CoreSDK {
207
375
  });
208
376
  }
209
377
 
378
+ /**
379
+ * Returns offer from subgraph.
380
+ * @param offerId - ID of offer.
381
+ * @param queryVars - Optional query variables to skip, order or filter.
382
+ * @returns Offer entity from subgraph.
383
+ */
210
384
  public async getOfferById(
211
385
  offerId: BigNumberish,
212
386
  queryVars?: offers.subgraph.SingleOfferQueryVariables
@@ -214,36 +388,27 @@ export class CoreSDK {
214
388
  return offers.subgraph.getOfferById(this._subgraphUrl, offerId, queryVars);
215
389
  }
216
390
 
391
+ /**
392
+ * Returns offers from subgraph.
393
+ * @param queryVars - Optional query variables to skip, order or filter.
394
+ * @returns Offer entities from subgraph.
395
+ */
217
396
  public async getOffers(
218
397
  queryVars?: subgraph.GetOffersQueryQueryVariables
219
398
  ): Promise<subgraph.OfferFieldsFragment[]> {
220
399
  return offers.subgraph.getOffers(this._subgraphUrl, queryVars);
221
400
  }
222
401
 
223
- public async commitToOffer(
224
- offerId: BigNumberish,
225
- overrides: Partial<{
226
- buyer: string;
227
- }> = {}
228
- ): Promise<TransactionResponse> {
229
- return exchanges.handler.commitToOffer({
230
- buyer: overrides.buyer || (await this._web3Lib.getSignerAddress()),
231
- offerId,
232
- web3Lib: this._web3Lib,
233
- subgraphUrl: this._subgraphUrl,
234
- contractAddress: this._protocolDiamond
235
- });
236
- }
237
-
238
- public getCommittedExchangeIdFromLogs(logs: Log[]): string | null {
239
- return getValueFromLogs({
240
- iface: exchanges.iface.bosonExchangeHandlerIface,
241
- logs,
242
- eventArgsKey: "exchangeId",
243
- eventName: "BuyerCommitted"
244
- });
245
- }
402
+ /* -------------------------------------------------------------------------- */
403
+ /* ERC20 / Exchange Token related methods */
404
+ /* -------------------------------------------------------------------------- */
246
405
 
406
+ /**
407
+ * Returns the current allowance of the given token by calling the contract.
408
+ * @param exchangeToken - Address of exchange token.
409
+ * @param overrides - Optional overrides.
410
+ * @returns Allowance for given signer.
411
+ */
247
412
  public async getExchangeTokenAllowance(
248
413
  exchangeToken: string,
249
414
  overrides: Partial<{
@@ -259,6 +424,11 @@ export class CoreSDK {
259
424
  });
260
425
  }
261
426
 
427
+ /**
428
+ * Returns `name`, `decimals` and `symbol` of the given token by calling the contract.
429
+ * @param exchangeToken - Address exchange token.
430
+ * @returns Decimals, name and symbol.
431
+ */
262
432
  public async getExchangeTokenInfo(exchangeToken: string): Promise<{
263
433
  name: string;
264
434
  decimals: number;
@@ -277,6 +447,13 @@ export class CoreSDK {
277
447
  return { decimals, name, symbol };
278
448
  }
279
449
 
450
+ /**
451
+ * Approves the given amount for the main protocol contract.
452
+ * @param exchangeToken - Address of token to approve.
453
+ * @param value - Amount of allowance.
454
+ * @param overrides - Optional overrides.
455
+ * @returns Transaction response.
456
+ */
280
457
  public async approveExchangeToken(
281
458
  exchangeToken: string,
282
459
  value: BigNumberish,
@@ -292,6 +469,17 @@ export class CoreSDK {
292
469
  });
293
470
  }
294
471
 
472
+ /* -------------------------------------------------------------------------- */
473
+ /* Funds related methods */
474
+ /* -------------------------------------------------------------------------- */
475
+
476
+ /**
477
+ * Deposit funds by calling the `FundsHandlerFacet` contract.
478
+ * @param sellerId - ID of seller account to deposit funds for.
479
+ * @param fundsAmount - Amount of funds.
480
+ * @param fundsTokenAddress - Address of funds token.
481
+ * @returns Transaction response.
482
+ */
295
483
  public async depositFunds(
296
484
  sellerId: BigNumberish,
297
485
  fundsAmount: BigNumberish,
@@ -306,6 +494,12 @@ export class CoreSDK {
306
494
  });
307
495
  }
308
496
 
497
+ /**
498
+ * Returns funds entity from subgraph.
499
+ * @param fundsId - ID of funds entity.
500
+ * @param queryVars - Optional query variables to skip, order or filter.
501
+ * @returns Funds entity from subgraph.
502
+ */
309
503
  public async getFundsById(
310
504
  fundsId: BigNumberish,
311
505
  queryVars?: subgraph.GetFundsByIdQueryVariables
@@ -313,12 +507,24 @@ export class CoreSDK {
313
507
  return funds.subgraph.getFundsById(this._subgraphUrl, fundsId, queryVars);
314
508
  }
315
509
 
510
+ /**
511
+ * Returns funds entities from subgraph.
512
+ * @param queryVars - Optional query variables to skip, order or filter.
513
+ * @returns Funds entities from subgraph.
514
+ */
316
515
  public async getFunds(
317
516
  queryVars?: subgraph.GetFundsQueryVariables
318
517
  ): Promise<subgraph.FundsEntityFieldsFragment[]> {
319
518
  return funds.subgraph.getFunds(this._subgraphUrl, queryVars);
320
519
  }
321
520
 
521
+ /**
522
+ * Withdraw selected funds by calling the `FundsHandlerFacet` contract.
523
+ * @param sellerId - ID of seller account to withdraw funds for.
524
+ * @param tokensToWithdraw - Addresses of funds tokens to withdraw.
525
+ * @param amountsToWithdraw - Amounts of funds token to withdraw.
526
+ * @returns Transaction response.
527
+ */
322
528
  public async withdrawFunds(
323
529
  sellerId: BigNumberish,
324
530
  tokensToWithdraw: Array<string>,
@@ -333,6 +539,11 @@ export class CoreSDK {
333
539
  });
334
540
  }
335
541
 
542
+ /**
543
+ * Withdraw all available funds by calling the `FundsHandlerFacet` contract.
544
+ * @param sellerId - ID of seller account to withdraw funds for.
545
+ * @returns Transaction response.
546
+ */
336
547
  public async withdrawAllAvailableFunds(
337
548
  sellerId: BigNumberish
338
549
  ): Promise<TransactionResponse> {
@@ -344,6 +555,16 @@ export class CoreSDK {
344
555
  });
345
556
  }
346
557
 
558
+ /* -------------------------------------------------------------------------- */
559
+ /* Exchange related methods */
560
+ /* -------------------------------------------------------------------------- */
561
+
562
+ /**
563
+ * Returns exchange entity from subgraph.
564
+ * @param exchangeId - ID of exchange entity.
565
+ * @param queryVars - Optional query variables to skip, order or filter.
566
+ * @returns Exchange entity from subgraph.
567
+ */
347
568
  public async getExchangeById(
348
569
  exchangeId: BigNumberish,
349
570
  queryVars?: subgraph.GetExchangeByIdQueryQueryVariables
@@ -355,12 +576,59 @@ export class CoreSDK {
355
576
  );
356
577
  }
357
578
 
579
+ /**
580
+ * Returns exchange entities from subgraph.
581
+ * @param queryVars - Optional query variables to skip, order or filter.
582
+ * @returns Exchange entities from subgraph.
583
+ */
358
584
  public async getExchanges(
359
585
  queryVars?: subgraph.GetExchangesQueryQueryVariables
360
586
  ): Promise<subgraph.ExchangeFieldsFragment[]> {
361
587
  return exchanges.subgraph.getExchanges(this._subgraphUrl, queryVars);
362
588
  }
363
589
 
590
+ /**
591
+ * Commits to an offer by calling the `ExchangeHandlerContract`.
592
+ * This transaction only succeeds if the seller has deposited funds.
593
+ * @param offerId - ID of offer to commit to.
594
+ * @param overrides - Optional overrides.
595
+ * @returns Transaction response.
596
+ */
597
+ public async commitToOffer(
598
+ offerId: BigNumberish,
599
+ overrides: Partial<{
600
+ buyer: string;
601
+ }> = {}
602
+ ): Promise<TransactionResponse> {
603
+ return exchanges.handler.commitToOffer({
604
+ buyer: overrides.buyer || (await this._web3Lib.getSignerAddress()),
605
+ offerId,
606
+ web3Lib: this._web3Lib,
607
+ subgraphUrl: this._subgraphUrl,
608
+ contractAddress: this._protocolDiamond
609
+ });
610
+ }
611
+
612
+ /**
613
+ * Utility method to retrieve the created `exchangeId` from logs after calling `commitToOffer`.
614
+ * @param logs - Logs to search in.
615
+ * @returns Created exchange id.
616
+ */
617
+ public getCommittedExchangeIdFromLogs(logs: Log[]): string | null {
618
+ return getValueFromLogs({
619
+ iface: exchanges.iface.bosonExchangeHandlerIface,
620
+ logs,
621
+ eventArgsKey: "exchangeId",
622
+ eventName: "BuyerCommitted"
623
+ });
624
+ }
625
+
626
+ /**
627
+ * Revokes an existing voucher by calling the `ExchangeHandlerContract`.
628
+ * Callable by seller `operator`.
629
+ * @param exchangeId - ID of exchange to revoke.
630
+ * @returns Transaction response.
631
+ */
364
632
  public async revokeVoucher(
365
633
  exchangeId: BigNumberish
366
634
  ): Promise<TransactionResponse> {
@@ -372,6 +640,12 @@ export class CoreSDK {
372
640
  });
373
641
  }
374
642
 
643
+ /**
644
+ * Cancels an existing voucher by calling the `ExchangeHandlerContract`.
645
+ * Callable by buyer.
646
+ * @param exchangeId - ID of exchange to cancel.
647
+ * @returns Transaction response.
648
+ */
375
649
  public async cancelVoucher(
376
650
  exchangeId: BigNumberish
377
651
  ): Promise<TransactionResponse> {
@@ -383,6 +657,12 @@ export class CoreSDK {
383
657
  });
384
658
  }
385
659
 
660
+ /**
661
+ * Redeems an existing voucher by calling the `ExchangeHandlerContract`.
662
+ * Callable by buyer.
663
+ * @param exchangeId - ID of exchange to redeem.
664
+ * @returns Transaction response.
665
+ */
386
666
  public async redeemVoucher(
387
667
  exchangeId: BigNumberish
388
668
  ): Promise<TransactionResponse> {
@@ -394,6 +674,12 @@ export class CoreSDK {
394
674
  });
395
675
  }
396
676
 
677
+ /**
678
+ * Completes an existing voucher by calling the `ExchangeHandlerContract`.
679
+ * Callable by buyer or seller operator.
680
+ * @param exchangeId - ID of exchange to complete.
681
+ * @returns Transaction response.
682
+ */
397
683
  public async completeExchange(
398
684
  exchangeId: BigNumberish
399
685
  ): Promise<TransactionResponse> {
@@ -405,6 +691,11 @@ export class CoreSDK {
405
691
  });
406
692
  }
407
693
 
694
+ /**
695
+ * Expires an existing voucher by calling the `ExchangeHandlerContract`.
696
+ * @param exchangeId - ID of exchange to expire.
697
+ * @returns Transaction response.
698
+ */
408
699
  public async expireVoucher(
409
700
  exchangeId: BigNumberish
410
701
  ): Promise<TransactionResponse> {
@@ -416,6 +707,15 @@ export class CoreSDK {
416
707
  });
417
708
  }
418
709
 
710
+ /* -------------------------------------------------------------------------- */
711
+ /* Meta Tx related methods */
712
+ /* -------------------------------------------------------------------------- */
713
+
714
+ /**
715
+ * Encodes and signs a meta transaction that can be relayed.
716
+ * @param args - Meta transaction args.
717
+ * @returns Signature.
718
+ */
419
719
  public async signExecuteMetaTx(
420
720
  args: Omit<
421
721
  Parameters<typeof metaTx.handler.signExecuteMetaTx>[0],
@@ -1,2 +1,3 @@
1
1
  export * as handler from "./handler";
2
2
  export * as iface from "./interface";
3
+ export * as subgraph from "./subgraph";
@@ -0,0 +1,84 @@
1
+ query getExchangeTokenByIdQuery(
2
+ $exchangeTokenId: ID!
3
+ $exchangeTokensSkip: Int
4
+ $exchangeTokensFirst: Int
5
+ $exchangeTokensOrderBy: ExchangeToken_orderBy
6
+ $exchangeTokensOrderDirection: OrderDirection
7
+ $exchangeTokensFilter: ExchangeToken_filter
8
+ $offersSkip: Int
9
+ $offersFirst: Int
10
+ $offersOrderBy: Offer_orderBy
11
+ $offersOrderDirection: OrderDirection
12
+ $offersFilter: Offer_filter
13
+ $fundsSkip: Int
14
+ $fundsFirst: Int
15
+ $fundsOrderBy: FundsEntity_orderBy
16
+ $fundsOrderDirection: OrderDirection
17
+ $fundsFilter: FundsEntity_filter
18
+ $includeOffers: Boolean = false
19
+ $includeFunds: Boolean = false
20
+ ) {
21
+ exchangeToken(id: $exchangeTokenId) {
22
+ ...ExchangeTokenFields
23
+ }
24
+ }
25
+
26
+ query getExchangeTokensQuery(
27
+ $exchangeTokensSkip: Int
28
+ $exchangeTokensFirst: Int
29
+ $exchangeTokensOrderBy: ExchangeToken_orderBy
30
+ $exchangeTokensOrderDirection: OrderDirection
31
+ $exchangeTokensFilter: ExchangeToken_filter
32
+ $offersSkip: Int
33
+ $offersFirst: Int
34
+ $offersOrderBy: Offer_orderBy
35
+ $offersOrderDirection: OrderDirection
36
+ $offersFilter: Offer_filter
37
+ $includeOffers: Boolean = false
38
+ $fundsSkip: Int
39
+ $fundsFirst: Int
40
+ $fundsOrderBy: FundsEntity_orderBy
41
+ $fundsOrderDirection: OrderDirection
42
+ $fundsFilter: FundsEntity_filter
43
+ $includeFunds: Boolean = false
44
+ ) {
45
+ exchangeTokens(
46
+ skip: $exchangeTokensSkip
47
+ first: $exchangeTokensFirst
48
+ orderBy: $exchangeTokensOrderBy
49
+ orderDirection: $exchangeTokensOrderDirection
50
+ where: $exchangeTokensFilter
51
+ ) {
52
+ ...ExchangeTokenFields
53
+ }
54
+ }
55
+
56
+ fragment ExchangeTokenFields on ExchangeToken {
57
+ ...BaseExchangeTokenFields
58
+ offers(
59
+ skip: $offersSkip
60
+ first: $offersFirst
61
+ orderBy: $offersOrderBy
62
+ orderDirection: $offersOrderDirection
63
+ where: $offersFilter
64
+ ) @include(if: $includeOffers) {
65
+ ...BaseOfferFields
66
+ }
67
+ funds(
68
+ skip: $fundsSkip
69
+ first: $fundsFirst
70
+ orderBy: $fundsOrderBy
71
+ orderDirection: $fundsOrderDirection
72
+ where: $fundsFilter
73
+ ) @include(if: $includeFunds) {
74
+ ...BaseFundsEntityFields
75
+ }
76
+ }
77
+
78
+ fragment BaseExchangeTokenFields on ExchangeToken {
79
+ id
80
+ address
81
+ decimals
82
+ symbol
83
+ name
84
+ }
@@ -0,0 +1,33 @@
1
+ import { getSubgraphSdk } from "../utils/graphql";
2
+ import {
3
+ ExchangeTokenFieldsFragment,
4
+ GetExchangeTokenByIdQueryQueryVariables,
5
+ GetExchangeTokensQueryQueryVariables
6
+ } from "../subgraph";
7
+
8
+ export type SingleExchangeTokenQueryVariables = Omit<
9
+ GetExchangeTokenByIdQueryQueryVariables,
10
+ "exchangeTokenId"
11
+ >;
12
+
13
+ export async function getExchangeTokenById(
14
+ subgraphUrl: string,
15
+ exchangeTokenId: string,
16
+ queryVars: SingleExchangeTokenQueryVariables = {}
17
+ ): Promise<ExchangeTokenFieldsFragment> {
18
+ const sdk = getSubgraphSdk(subgraphUrl);
19
+ const { exchangeToken } = await sdk.getExchangeTokenByIdQuery({
20
+ exchangeTokenId: exchangeTokenId.toLowerCase(),
21
+ ...queryVars
22
+ });
23
+ return exchangeToken;
24
+ }
25
+
26
+ export async function getExchangeTokens(
27
+ subgraphUrl: string,
28
+ queryVars: GetExchangeTokensQueryQueryVariables = {}
29
+ ): Promise<ExchangeTokenFieldsFragment[]> {
30
+ const sdk = getSubgraphSdk(subgraphUrl);
31
+ const { exchangeTokens = [] } = await sdk.getExchangeTokensQuery(queryVars);
32
+ return exchangeTokens;
33
+ }
@@ -23,13 +23,14 @@ query getFunds(
23
23
  }
24
24
 
25
25
  fragment FundsEntityFields on FundsEntity {
26
- id
27
- availableAmount
26
+ ...BaseFundsEntityFields
28
27
  token {
29
- address
30
- name
31
- symbol
32
- decimals
28
+ ...BaseExchangeTokenFields
33
29
  }
30
+ }
31
+
32
+ fragment BaseFundsEntityFields on FundsEntity {
33
+ id
34
+ availableAmount
34
35
  accountId
35
36
  }