@bosonprotocol/core-sdk 1.23.0-alpha.16 → 1.23.0-alpha.18

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 (128) hide show
  1. package/dist/cjs/accounts/mixin.d.ts +194 -0
  2. package/dist/cjs/accounts/mixin.d.ts.map +1 -0
  3. package/dist/cjs/accounts/mixin.js +426 -0
  4. package/dist/cjs/accounts/mixin.js.map +1 -0
  5. package/dist/cjs/core-sdk.d.ts +16 -818
  6. package/dist/cjs/core-sdk.d.ts.map +1 -1
  7. package/dist/cjs/core-sdk.js +26 -1579
  8. package/dist/cjs/core-sdk.js.map +1 -1
  9. package/dist/cjs/disputes/mixin.d.ts +113 -0
  10. package/dist/cjs/disputes/mixin.d.ts.map +1 -0
  11. package/dist/cjs/disputes/mixin.js +203 -0
  12. package/dist/cjs/disputes/mixin.js.map +1 -0
  13. package/dist/cjs/event-logs/mixin.d.ts +11 -0
  14. package/dist/cjs/event-logs/mixin.d.ts.map +1 -0
  15. package/dist/cjs/event-logs/mixin.js +28 -0
  16. package/dist/cjs/event-logs/mixin.js.map +1 -0
  17. package/dist/cjs/exchanges/mixin.d.ts +77 -0
  18. package/dist/cjs/exchanges/mixin.d.ts.map +1 -0
  19. package/dist/cjs/exchanges/mixin.js +172 -0
  20. package/dist/cjs/exchanges/mixin.js.map +1 -0
  21. package/dist/cjs/funds/mixin.d.ts +42 -0
  22. package/dist/cjs/funds/mixin.d.ts.map +1 -0
  23. package/dist/cjs/funds/mixin.js +95 -0
  24. package/dist/cjs/funds/mixin.js.map +1 -0
  25. package/dist/cjs/groups/mixin.d.ts +14 -0
  26. package/dist/cjs/groups/mixin.d.ts.map +1 -0
  27. package/dist/cjs/groups/mixin.js +33 -0
  28. package/dist/cjs/groups/mixin.js.map +1 -0
  29. package/dist/cjs/meta-tx/mixin.d.ts +176 -0
  30. package/dist/cjs/meta-tx/mixin.d.ts.map +1 -0
  31. package/dist/cjs/meta-tx/mixin.js +296 -0
  32. package/dist/cjs/meta-tx/mixin.js.map +1 -0
  33. package/dist/cjs/metadata/mixin.d.ts +40 -0
  34. package/dist/cjs/metadata/mixin.d.ts.map +1 -0
  35. package/dist/cjs/metadata/mixin.js +102 -0
  36. package/dist/cjs/metadata/mixin.js.map +1 -0
  37. package/dist/cjs/mixins/base-core-sdk.d.ts +41 -0
  38. package/dist/cjs/mixins/base-core-sdk.d.ts.map +1 -0
  39. package/dist/cjs/mixins/base-core-sdk.js +51 -0
  40. package/dist/cjs/mixins/base-core-sdk.js.map +1 -0
  41. package/dist/cjs/native-meta-tx/mixin.d.ts +35 -0
  42. package/dist/cjs/native-meta-tx/mixin.d.ts.map +1 -0
  43. package/dist/cjs/native-meta-tx/mixin.js +68 -0
  44. package/dist/cjs/native-meta-tx/mixin.js.map +1 -0
  45. package/dist/cjs/offers/mixin.d.ts +132 -0
  46. package/dist/cjs/offers/mixin.d.ts.map +1 -0
  47. package/dist/cjs/offers/mixin.js +292 -0
  48. package/dist/cjs/offers/mixin.js.map +1 -0
  49. package/dist/cjs/orchestration/mixin.d.ts +28 -0
  50. package/dist/cjs/orchestration/mixin.d.ts.map +1 -0
  51. package/dist/cjs/orchestration/mixin.js +59 -0
  52. package/dist/cjs/orchestration/mixin.js.map +1 -0
  53. package/dist/cjs/subgraph.d.ts +48 -24
  54. package/dist/cjs/subgraph.d.ts.map +1 -1
  55. package/dist/cjs/subgraph.js +1 -1
  56. package/dist/cjs/subgraph.js.map +1 -1
  57. package/dist/esm/accounts/mixin.d.ts +194 -0
  58. package/dist/esm/accounts/mixin.d.ts.map +1 -0
  59. package/dist/esm/accounts/mixin.js +342 -0
  60. package/dist/esm/accounts/mixin.js.map +1 -0
  61. package/dist/esm/core-sdk.d.ts +16 -818
  62. package/dist/esm/core-sdk.d.ts.map +1 -1
  63. package/dist/esm/core-sdk.js +27 -1483
  64. package/dist/esm/core-sdk.js.map +1 -1
  65. package/dist/esm/disputes/mixin.d.ts +113 -0
  66. package/dist/esm/disputes/mixin.d.ts.map +1 -0
  67. package/dist/esm/disputes/mixin.js +173 -0
  68. package/dist/esm/disputes/mixin.js.map +1 -0
  69. package/dist/esm/event-logs/mixin.d.ts +11 -0
  70. package/dist/esm/event-logs/mixin.d.ts.map +1 -0
  71. package/dist/esm/event-logs/mixin.js +13 -0
  72. package/dist/esm/event-logs/mixin.js.map +1 -0
  73. package/dist/esm/exchanges/mixin.d.ts +77 -0
  74. package/dist/esm/exchanges/mixin.d.ts.map +1 -0
  75. package/dist/esm/exchanges/mixin.js +141 -0
  76. package/dist/esm/exchanges/mixin.js.map +1 -0
  77. package/dist/esm/funds/mixin.d.ts +42 -0
  78. package/dist/esm/funds/mixin.d.ts.map +1 -0
  79. package/dist/esm/funds/mixin.js +72 -0
  80. package/dist/esm/funds/mixin.js.map +1 -0
  81. package/dist/esm/groups/mixin.d.ts +14 -0
  82. package/dist/esm/groups/mixin.d.ts.map +1 -0
  83. package/dist/esm/groups/mixin.js +18 -0
  84. package/dist/esm/groups/mixin.js.map +1 -0
  85. package/dist/esm/meta-tx/mixin.d.ts +176 -0
  86. package/dist/esm/meta-tx/mixin.d.ts.map +1 -0
  87. package/dist/esm/meta-tx/mixin.js +351 -0
  88. package/dist/esm/meta-tx/mixin.js.map +1 -0
  89. package/dist/esm/metadata/mixin.d.ts +40 -0
  90. package/dist/esm/metadata/mixin.d.ts.map +1 -0
  91. package/dist/esm/metadata/mixin.js +54 -0
  92. package/dist/esm/metadata/mixin.js.map +1 -0
  93. package/dist/esm/mixins/base-core-sdk.d.ts +41 -0
  94. package/dist/esm/mixins/base-core-sdk.d.ts.map +1 -0
  95. package/dist/esm/mixins/base-core-sdk.js +54 -0
  96. package/dist/esm/mixins/base-core-sdk.js.map +1 -0
  97. package/dist/esm/native-meta-tx/mixin.d.ts +35 -0
  98. package/dist/esm/native-meta-tx/mixin.d.ts.map +1 -0
  99. package/dist/esm/native-meta-tx/mixin.js +51 -0
  100. package/dist/esm/native-meta-tx/mixin.js.map +1 -0
  101. package/dist/esm/offers/mixin.d.ts +132 -0
  102. package/dist/esm/offers/mixin.d.ts.map +1 -0
  103. package/dist/esm/offers/mixin.js +232 -0
  104. package/dist/esm/offers/mixin.js.map +1 -0
  105. package/dist/esm/orchestration/mixin.d.ts +28 -0
  106. package/dist/esm/orchestration/mixin.d.ts.map +1 -0
  107. package/dist/esm/orchestration/mixin.js +42 -0
  108. package/dist/esm/orchestration/mixin.js.map +1 -0
  109. package/dist/esm/subgraph.d.ts +48 -24
  110. package/dist/esm/subgraph.d.ts.map +1 -1
  111. package/dist/esm/subgraph.js +1 -1
  112. package/dist/esm/subgraph.js.map +1 -1
  113. package/package.json +3 -3
  114. package/src/accounts/mixin.ts +484 -0
  115. package/src/core-sdk.ts +42 -2103
  116. package/src/disputes/mixin.ts +240 -0
  117. package/src/event-logs/mixin.ts +16 -0
  118. package/src/exchanges/mixin.ts +184 -0
  119. package/src/funds/mixin.ts +99 -0
  120. package/src/groups/mixin.ts +24 -0
  121. package/src/meta-tx/mixin.ts +515 -0
  122. package/src/metadata/mixin.ts +85 -0
  123. package/src/mixins/base-core-sdk.ts +96 -0
  124. package/src/native-meta-tx/mixin.ts +77 -0
  125. package/src/offers/mixin.ts +322 -0
  126. package/src/offers/queries.graphql +1 -1
  127. package/src/orchestration/mixin.ts +57 -0
  128. package/src/subgraph.ts +49 -25
package/src/core-sdk.ts CHANGED
@@ -1,77 +1,25 @@
1
- import { ITokenInfo, TokenInfoManager } from "./utils/tokenInfoManager";
1
+ import { OrchestrationMixin } from "./orchestration/mixin";
2
+ import { GroupsMixin } from "./groups/mixin";
3
+ import { NativeMetaTxMixin } from "./native-meta-tx/mixin";
4
+ import { MetaTxMixin } from "./meta-tx/mixin";
5
+ import { DisputesMixin } from "./disputes/mixin";
6
+ import { applyMixins, BaseCoreSDK } from "./mixins/base-core-sdk";
2
7
  import {
3
8
  Web3LibAdapter,
4
- TransactionResponse,
5
9
  getDefaultConfig,
6
10
  MetadataStorage,
7
- AnyMetadata,
8
- Log,
9
- MetaTxConfig,
10
- LensContracts,
11
- AuthTokenType,
12
- CreateGroupArgs,
13
- ConditionStruct
11
+ MetaTxConfig
14
12
  } from "@bosonprotocol/common";
15
- import { BigNumber, BigNumberish } from "@ethersproject/bignumber";
16
- import { AddressZero } from "@ethersproject/constants";
17
- import { BytesLike } from "@ethersproject/bytes";
18
13
  import { EnvironmentType } from "@bosonprotocol/common/src/types";
19
14
 
20
- import * as accounts from "./accounts";
21
- import * as disputes from "./disputes";
22
- import * as exchanges from "./exchanges";
23
- import * as offers from "./offers";
24
- import * as orchestration from "./orchestration";
25
- import * as groups from "./groups";
26
- import * as erc20 from "./erc20";
27
- import * as erc721 from "./erc721";
28
- import * as funds from "./funds";
29
- import * as metaTx from "./meta-tx";
30
- import * as nativeMetaTx from "./native-meta-tx";
31
- import * as metadata from "./metadata";
32
- import * as subgraph from "./subgraph";
33
- import * as eventLogs from "./event-logs";
34
-
35
- import { getValueFromLogs, getValuesFromLogs } from "./utils/logs";
36
- import { GetRetriedHashesData } from "./meta-tx/biconomy";
37
-
38
- export class CoreSDK {
39
- private _web3Lib: Web3LibAdapter;
40
- private _metadataStorage?: MetadataStorage;
41
- private _theGraphStorage?: MetadataStorage;
42
-
43
- private _subgraphUrl: string;
44
- private _protocolDiamond: string;
45
- private _chainId: number;
46
- private _tokenInfoManager: TokenInfoManager;
47
-
48
- private _metaTxConfig?: Partial<MetaTxConfig>;
49
- private _lensContracts?: LensContracts;
50
-
51
- /**
52
- * Creates an instance of `CoreSDK`
53
- * @param args - Constructor args
54
- */
55
- constructor(opts: {
56
- web3Lib: Web3LibAdapter;
57
- subgraphUrl: string;
58
- protocolDiamond: string;
59
- metadataStorage?: MetadataStorage;
60
- theGraphStorage?: MetadataStorage;
61
- chainId: number;
62
- metaTx?: Partial<MetaTxConfig>;
63
- lensContracts?: LensContracts;
64
- }) {
65
- this._web3Lib = opts.web3Lib;
66
- this._subgraphUrl = opts.subgraphUrl;
67
- this._protocolDiamond = opts.protocolDiamond;
68
- this._metadataStorage = opts.metadataStorage;
69
- this._theGraphStorage = opts.theGraphStorage;
70
- this._chainId = opts.chainId;
71
- this._metaTxConfig = opts.metaTx;
72
- this._lensContracts = opts.lensContracts;
73
- }
15
+ import { MetadataMixin } from "./metadata/mixin";
16
+ import { AccountsMixin } from "./accounts/mixin";
17
+ import { OfferMixin } from "./offers/mixin";
18
+ import { FundsMixin } from "./funds/mixin";
19
+ import { ExchangesMixin } from "./exchanges/mixin";
20
+ import { EventLogsMixin } from "./event-logs/mixin";
74
21
 
22
+ export class CoreSDK extends BaseCoreSDK {
75
23
  /**
76
24
  * Creates an instance of `CoreSDK` by using default values derived either from
77
25
  * `args.envName` or `args.chainId`.
@@ -140,2041 +88,32 @@ export class CoreSDK {
140
88
  !!this._metaTxConfig.relayerUrl
141
89
  );
142
90
  }
91
+ }
143
92
 
144
- /* -------------------------------------------------------------------------- */
145
- /* Metadata related methods */
146
- /* -------------------------------------------------------------------------- */
147
-
148
- /**
149
- * Stores supported offer metadata via the MetadataStorage instance which was passed in
150
- * at construction.
151
- * @param metadata - Offer metadata of type `BASE` or `PRODUCT_V1`.
152
- * @returns Metadata hash / identifier.
153
- */
154
- public async storeMetadata(metadata: AnyMetadata): Promise<string> {
155
- if (!this._metadataStorage) {
156
- throw new Error("No metadata storage set");
157
- }
158
-
159
- return this._metadataStorage.storeMetadata(metadata);
160
- }
161
-
162
- /**
163
- * Returns supported offer metadata from passed in `MetadataStorage` instance.
164
- * @param metadataHashOrUri - Metadata hash or uri that can be handled by the
165
- * storage instance.
166
- * @returns Offer metadata.
167
- */
168
- public async getMetadata(metadataHashOrUri: string): Promise<AnyMetadata> {
169
- if (!this._metadataStorage) {
170
- throw new Error("No metadata storage set");
171
- }
172
-
173
- return this._metadataStorage.getMetadata(metadataHashOrUri);
174
- }
175
-
176
- /**
177
- * Returns `BASE` type offer metadata entities from subgraph.
178
- * @param queryVars - Optional query variables to skip, order or filter.
179
- * @returns BaseMetadataEntities from subgraph.
180
- */
181
- public async getBaseMetadataEntities(
182
- queryVars?: subgraph.GetBaseMetadataEntitiesQueryQueryVariables
183
- ): Promise<subgraph.BaseMetadataEntityFieldsFragment[]> {
184
- return metadata.subgraph.getBaseMetadataEntities(
185
- this._subgraphUrl,
186
- queryVars
187
- );
188
- }
189
-
190
- /**
191
- * Returns `PRODUCT_V1` type offer metadata entities from subgraph.
192
- * @param queryVars - Optional query variables to skip, order or filter.
193
- * @returns ProductV1MetadataEntities from subgraph.
194
- */
195
- public async getProductV1MetadataEntities(
196
- queryVars?: subgraph.GetProductV1MetadataEntitiesQueryQueryVariables
197
- ): Promise<subgraph.ProductV1MetadataEntityFieldsFragment[]> {
198
- return metadata.subgraph.getProductV1MetadataEntities(
199
- this._subgraphUrl,
200
- queryVars
201
- );
202
- }
203
-
204
- public async getProductV1Products(
205
- queryVars?: subgraph.GetProductV1ProductsQueryQueryVariables
206
- ): Promise<subgraph.BaseProductV1ProductFieldsFragment[]> {
207
- return metadata.subgraph.getProductV1Products(this._subgraphUrl, queryVars);
208
- }
209
-
210
- public async getProductWithVariants(productUuid: string): Promise<{
211
- product: subgraph.BaseProductV1ProductFieldsFragment;
212
- variants: Array<{
213
- offer: subgraph.OfferFieldsFragment;
214
- variations: Array<subgraph.ProductV1Variation>;
215
- }>;
216
- } | null> {
217
- return metadata.subgraph.getProductWithVariants(
218
- this._subgraphUrl,
219
- productUuid
220
- );
221
- }
222
-
223
- /* -------------------------------------------------------------------------- */
224
- /* Account related methods */
225
- /* -------------------------------------------------------------------------- */
226
-
227
- /* --------------------------------- Seller --------------------------------- */
228
-
229
- /**
230
- * Returns seller entity from subgraph.
231
- * @param sellerId - ID of seller entity to query for.
232
- * @param queryVars - Optional query variables to skip, order or filter.
233
- * @returns Seller entity from subgraph.
234
- */
235
- public async getSellerById(
236
- sellerId: BigNumberish,
237
- queryVars?: accounts.subgraph.SingleSellerQueryVariables
238
- ): Promise<subgraph.SellerFieldsFragment> {
239
- return accounts.subgraph.getSellerById(
240
- this._subgraphUrl,
241
- sellerId,
242
- queryVars
243
- );
244
- }
245
-
246
- /**
247
- * Returns seller entity from subgraph.
248
- * @param operator - Operator address of seller entity to query for.
249
- * @param queryVars - Optional query variables to skip, order or filter.
250
- * @returns Seller entity from subgraph.
251
- */
252
- public async getSellerByOperator(
253
- operator: string,
254
- queryVars?: subgraph.GetSellersQueryQueryVariables
255
- ): Promise<subgraph.SellerFieldsFragment> {
256
- return accounts.subgraph.getSellerByOperator(
257
- this._subgraphUrl,
258
- operator,
259
- queryVars
260
- );
261
- }
262
-
263
- /**
264
- * Returns seller entity from subgraph.
265
- * @param clerk - Clerk address of seller entity to query for.
266
- * @param queryVars - Optional query variables to skip, order or filter.
267
- * @returns Seller entity from subgraph.
268
- */
269
- public async getSellerByClerk(
270
- clerk: string,
271
- queryVars?: subgraph.GetSellersQueryQueryVariables
272
- ): Promise<subgraph.SellerFieldsFragment> {
273
- return accounts.subgraph.getSellerByClerk(
274
- this._subgraphUrl,
275
- clerk,
276
- queryVars
277
- );
278
- }
279
-
280
- /**
281
- * Returns seller entity from subgraph.
282
- * @param admin - Admin address of seller entity to query for.
283
- * @param queryVars - Optional query variables to skip, order or filter.
284
- * @returns Seller entity from subgraph.
285
- */
286
- public async getSellerByAdmin(
287
- admin: string,
288
- queryVars?: subgraph.GetSellersQueryQueryVariables
289
- ): Promise<subgraph.SellerFieldsFragment> {
290
- return accounts.subgraph.getSellerByAdmin(
291
- this._subgraphUrl,
292
- admin,
293
- queryVars
294
- );
295
- }
296
-
297
- /**
298
- * Returns seller entity from subgraph.
299
- * @param treasury - Treasury address of seller entity to query for.
300
- * @param queryVars - Optional query variables to skip, order or filter.
301
- * @returns Seller entity from subgraph.
302
- */
303
- public async getSellerByTreasury(
304
- treasury: string,
305
- queryVars?: subgraph.GetSellersQueryQueryVariables
306
- ): Promise<subgraph.SellerFieldsFragment> {
307
- return accounts.subgraph.getSellerByTreasury(
308
- this._subgraphUrl,
309
- treasury,
310
- queryVars
311
- );
312
- }
313
-
314
- /**
315
- * Returns seller entity from subgraph. Matches `operator`, `clerk`, `admin` or `treasury`.
316
- * @param address - Address of seller entity to query for.
317
- * @param queryVars - Optional query variables to skip, order or filter.
318
- * @returns Seller entity from subgraph.
319
- */
320
- public async getSellersByAddress(
321
- address: string,
322
- queryVars?: subgraph.GetSellersQueryQueryVariables
323
- ): Promise<subgraph.SellerFieldsFragment[]> {
324
- if (address === AddressZero) {
325
- throw new Error(`Unsupported search address '${AddressZero}'`);
326
- }
327
- const seller = await accounts.subgraph.getSellerByAddress(
328
- this._subgraphUrl,
329
- address,
330
- queryVars
331
- );
332
- if (!seller && this._lensContracts?.LENS_HUB_CONTRACT) {
333
- // If seller is not found per address, try to find per authToken
334
- const tokenType = AuthTokenType.LENS; // only LENS for now
335
- const tokenIds = await this.fetchUserAuthTokens(address, tokenType);
336
- const promises: Promise<subgraph.SellerFieldsFragment>[] = [];
337
- for (const tokenId of tokenIds) {
338
- // Just in case the user owns several auth tokens
339
- const sellerPromise = this.getSellerByAuthToken(
340
- tokenId,
341
- tokenType,
342
- queryVars
343
- );
344
- promises.push(sellerPromise);
345
- }
346
- return (await Promise.all(promises)).filter((seller) => !!seller);
347
- }
348
- return [seller].filter((seller) => !!seller);
349
- }
350
-
351
- /**
352
- * Returns the array of LENS tokenIds owned by a specified address
353
- * @param address - Address of seller entity to query for.
354
- * @param queryVars - Optional query variables to skip, order or filter.
355
- * @returns Array of tokenIds
356
- */
357
- public async fetchUserAuthTokens(
358
- address: string,
359
- tokenType: number
360
- ): Promise<Array<string>> {
361
- if (tokenType !== AuthTokenType.LENS) {
362
- // only LENS for now
363
- throw new Error(`Unsupported authTokenType '${tokenType}'`);
364
- }
365
- if (!this._lensContracts || !this._lensContracts?.LENS_HUB_CONTRACT) {
366
- throw new Error("LENS contract is not configured in Core-SDK");
367
- }
368
- const balance = await erc721.handler.balanceOf({
369
- contractAddress: this._lensContracts?.LENS_HUB_CONTRACT,
370
- owner: address,
371
- web3Lib: this._web3Lib
372
- });
373
-
374
- const balanceBN = BigNumber.from(balance);
375
- const promises: Promise<string>[] = [];
376
- for (let index = 0; balanceBN.gt(index); index++) {
377
- const tokenIdPromise = erc721.handler.tokenOfOwnerByIndex({
378
- contractAddress: this._lensContracts?.LENS_HUB_CONTRACT,
379
- owner: address,
380
- index,
381
- web3Lib: this._web3Lib
382
- });
383
- promises.push(tokenIdPromise);
384
- }
385
- const ret = await Promise.all(promises);
386
- return ret;
387
- }
388
-
389
- /**
390
- * Returns seller entity from subgraph that owns the given auth token (if any).
391
- * @param tokenId - tokenId of the Auth Token.
392
- * @param tokenType - Type of the Auth Token (1 for LENS, ...).
393
- * @param queryVars - Optional query variables to skip, order or filter.
394
- * @returns Seller entity from subgraph.
395
- */
396
- public async getSellerByAuthToken(
397
- tokenId: string,
398
- tokenType: number,
399
- queryVars?: subgraph.GetSellersQueryQueryVariables
400
- ): Promise<subgraph.SellerFieldsFragment> {
401
- if (tokenType !== AuthTokenType.LENS) {
402
- // only LENS for now
403
- throw new Error(`Unsupported authTokenType '${tokenType}'`);
404
- }
405
- return accounts.subgraph.getSellerByAuthToken(
406
- this._subgraphUrl,
407
- tokenId,
408
- tokenType,
409
- queryVars
410
- );
411
- }
412
-
413
- /**
414
- * Returns seller entities from subgraph.
415
- * @param queryVars - Optional query variables to skip, order or filter.
416
- * @returns Seller entities from subgraph.
417
- */
418
- public async getSellers(
419
- queryVars?: subgraph.GetSellersQueryQueryVariables
420
- ): Promise<subgraph.SellerFieldsFragment[]> {
421
- return accounts.subgraph.getSellers(this._subgraphUrl, queryVars);
422
- }
423
-
424
- /**
425
- * Creates seller account by calling the `AccountHandlerFacet` contract.
426
- * @param sellerToCreate - Addresses and contract URI to set in the seller account.
427
- * @param overrides - Optional overrides.
428
- * @returns Transaction response.
429
- */
430
- public async createSeller(
431
- sellerToCreate: accounts.CreateSellerArgs,
432
- overrides: Partial<{
433
- contractAddress: string;
434
- }> = {}
435
- ): Promise<TransactionResponse> {
436
- return accounts.handler.createSeller({
437
- sellerToCreate,
438
- web3Lib: this._web3Lib,
439
- contractAddress: overrides.contractAddress || this._protocolDiamond
440
- });
441
- }
442
-
443
- /**
444
- * Creates seller account and offer by calling the `OrchestrationHandlerFacet` contract.
445
- * This transaction only succeeds if there is no existing seller account for the connected signer.
446
- * @param sellerToCreate - Addresses to set in the seller account.
447
- * @param offerToCreate - Offer arguments.
448
- * @param overrides - Optional overrides.
449
- * @returns Transaction response.
450
- */
451
- public async createSellerAndOffer(
452
- sellerToCreate: accounts.CreateSellerArgs,
453
- offerToCreate: offers.CreateOfferArgs,
454
- overrides: Partial<{
455
- contractAddress: string;
456
- }> = {}
457
- ): Promise<TransactionResponse> {
458
- return orchestration.handler.createOfferAndSeller({
459
- sellerToCreate,
460
- offerToCreate,
461
- web3Lib: this._web3Lib,
462
- theGraphStorage: this._theGraphStorage,
463
- metadataStorage: this._metadataStorage,
464
- contractAddress: overrides.contractAddress || this._protocolDiamond
465
- });
466
- }
467
-
468
- /**
469
- * Updates seller account by calling the `AccountHandlerFacet` contract. Only callable
470
- * by admin.
471
- * @param sellerUpdates - Values to update.
472
- * @param overrides - Optional overrides.
473
- * @returns Transaction response.
474
- */
475
- public async updateSeller(
476
- sellerUpdates: accounts.UpdateSellerArgs,
477
- overrides: Partial<{
478
- contractAddress: string;
479
- }> = {}
480
- ): Promise<TransactionResponse> {
481
- return accounts.handler.updateSeller({
482
- sellerUpdates,
483
- web3Lib: this._web3Lib,
484
- contractAddress: overrides.contractAddress || this._protocolDiamond
485
- });
486
- }
487
-
488
- /* ---------------------------------- Buyer --------------------------------- */
489
-
490
- /**
491
- * Returns buyer entity from subgraph.
492
- * @param buyerId - ID of buyer entity to query for.
493
- * @param queryVars - Optional query variables to skip, order or filter.
494
- * @returns Buyer entity from subgraph.
495
- */
496
- public async getBuyerById(
497
- buyerId: BigNumberish,
498
- queryVars?: accounts.subgraph.SingleBuyerQueryVariables
499
- ): Promise<subgraph.BuyerFieldsFragment> {
500
- return accounts.subgraph.getBuyerById(
501
- this._subgraphUrl,
502
- buyerId,
503
- queryVars
504
- );
505
- }
506
-
507
- /**
508
- * Returns buyer entities from subgraph.
509
- * @param queryVars - Optional query variables to skip, order or filter.
510
- * @returns Buyer entities from subgraph.
511
- */
512
- public async getBuyers(
513
- queryVars?: subgraph.GetBuyersQueryQueryVariables
514
- ): Promise<subgraph.BuyerFieldsFragment[]> {
515
- return accounts.subgraph.getBuyers(this._subgraphUrl, queryVars);
516
- }
517
-
518
- /* ---------------------------- Dispute Resolver ---------------------------- */
519
-
520
- /**
521
- * Creates a dispute resolver account by calling the `AccountHandlerFacet` contract.
522
- * @param disputeResolverToCreate - Dispute resolver arguments.
523
- * @returns Transaction response.
524
- */
525
- public async createDisputeResolver(
526
- disputeResolverToCreate: accounts.CreateDisputeResolverArgs
527
- ): Promise<TransactionResponse> {
528
- return accounts.handler.createDisputeResolver({
529
- disputeResolverToCreate,
530
- contractAddress: this._protocolDiamond,
531
- web3Lib: this._web3Lib
532
- });
533
- }
534
-
535
- /**
536
- * Utility method to retrieve the created `exchangeId` from logs after calling `commitToOffer`.
537
- * @param logs - Logs to search in.
538
- * @returns Created exchange id.
539
- */
540
- public getDisputeResolverIdFromLogs(logs: Log[]): string | null {
541
- return getValueFromLogs({
542
- iface: accounts.iface.bosonAccountHandlerIface,
543
- logs,
544
- eventArgsKey: "disputeResolverId",
545
- eventName: "DisputeResolverCreated"
546
- });
547
- }
548
-
549
- /**
550
- * Updates a dispute resolver account by calling the `AccountHandlerFacet` contract.
551
- * Note, that the caller must be the specified `admin` address of the dispute resolver account.
552
- * @param disputeResolverId - Id of dispute resolver to update.
553
- * @param updates - Values to update for the given dispute resolver.
554
- * @returns Transaction response.
555
- */
556
- public async updateDisputeResolver(
557
- disputeResolverId: BigNumberish,
558
- updates: accounts.DisputeResolverUpdates
559
- ): Promise<TransactionResponse> {
560
- return accounts.handler.updateDisputeResolver({
561
- disputeResolverId,
562
- updates,
563
- subgraphUrl: this._subgraphUrl,
564
- contractAddress: this._protocolDiamond,
565
- web3Lib: this._web3Lib
566
- });
567
- }
568
-
569
- /**
570
- * Activates a dispute resolver account by calling the `AccountHandlerFacet` contract.
571
- * Note, that the caller needs to have the ADMIN role.
572
- * @param disputeResolverId - Id of dispute resolver to activate.
573
- * @returns Transaction response.
574
- */
575
- public async activateDisputeResolver(
576
- disputeResolverId: BigNumberish
577
- ): Promise<TransactionResponse> {
578
- return accounts.handler.activateDisputeResolver({
579
- disputeResolverId,
580
- contractAddress: this._protocolDiamond,
581
- web3Lib: this._web3Lib
582
- });
583
- }
584
-
585
- /**
586
- * Adds fees to a dispute resolver account by calling the `AccountHandlerFacet`
587
- * contract. Note, that the caller must be the specified `admin` address of the dispute
588
- * resolver account.
589
- * @param disputeResolverId - Id of dispute resolver.
590
- * @param fees - Dispute resolution fees. Should only contain token addresses that are
591
- * not already specified.
592
- * @returns Transaction response.
593
- */
594
- public async addFeesToDisputeResolver(
595
- disputeResolverId: BigNumberish,
596
- fees: accounts.DisputeResolutionFee[]
597
- ): Promise<TransactionResponse> {
598
- return accounts.handler.addFeesToDisputeResolver({
599
- disputeResolverId,
600
- fees,
601
- contractAddress: this._protocolDiamond,
602
- web3Lib: this._web3Lib
603
- });
604
- }
605
-
606
- /**
607
- * Adds sellers to the allow list of a dispute resolver account by calling the
608
- * `AccountHandlerFacet` contract. Note, that the caller must be the specified
609
- * `admin` address of the dispute resolver account.
610
- * @param disputeResolverId - Id of dispute resolver.
611
- * @param sellerAllowList - List of seller ids that are allowed to use the dispute resolver.
612
- * Should only contain seller ids that are not part of the current allow list.
613
- * @returns Transaction response.
614
- */
615
- public async addSellersToDisputeResolverAllowList(
616
- disputeResolverId: BigNumberish,
617
- sellerAllowList: BigNumberish[]
618
- ): Promise<TransactionResponse> {
619
- return accounts.handler.addSellersToAllowList({
620
- disputeResolverId,
621
- sellerAllowList,
622
- contractAddress: this._protocolDiamond,
623
- web3Lib: this._web3Lib
624
- });
625
- }
626
-
627
- /**
628
- * Removes fees from a dispute resolver account by calling the `AccountHandlerFacet`
629
- * contract. Note, that the caller must be the specified `admin` address of the dispute
630
- * resolver account.
631
- * @param disputeResolverId - Id of dispute resolver.
632
- * @param feeTokenAddresses - Addresses of fee tokens to remove.
633
- * @returns Transaction response.
634
- */
635
- public async removeFeesFromDisputeResolver(
636
- disputeResolverId: BigNumberish,
637
- feeTokenAddresses: string[]
638
- ): Promise<TransactionResponse> {
639
- return accounts.handler.removeFeesFromDisputeResolver({
640
- disputeResolverId,
641
- feeTokenAddresses,
642
- contractAddress: this._protocolDiamond,
643
- web3Lib: this._web3Lib
644
- });
645
- }
646
-
647
- /**
648
- * Removes sellers from the allow list of a dispute resolver account by calling the
649
- * `AccountHandlerFacet` contract. Note, that the caller must be the specified
650
- * `admin` address of the dispute resolver account.
651
- * @param disputeResolverId - Id of dispute resolver.
652
- * @param sellerAllowList - List of seller ids that should be removed from the allow
653
- * list of a dispute resolver.
654
- * @returns Transaction response.
655
- */
656
- public async removeSellersFromDisputeResolverAllowList(
657
- disputeResolverId: BigNumberish,
658
- sellerAllowList: string[]
659
- ): Promise<TransactionResponse> {
660
- return accounts.handler.removeSellersFromAllowList({
661
- disputeResolverId,
662
- sellerAllowList,
663
- contractAddress: this._protocolDiamond,
664
- web3Lib: this._web3Lib
665
- });
666
- }
667
-
668
- /**
669
- * Returns dispute resolver entity from subgraph.
670
- * @param disputeResolverId - ID of dispute resolver entity to query for.
671
- * @param queryVars - Optional query variables to skip, order or filter.
672
- * @returns Dispute resolver entity from subgraph.
673
- */
674
- public async getDisputeResolverById(
675
- disputeResolverId: BigNumberish,
676
- queryVars?: accounts.subgraph.SingleDisputeResolverQueryVariables
677
- ): Promise<subgraph.DisputeResolverFieldsFragment> {
678
- return accounts.subgraph.getDisputeResolverById(
679
- this._subgraphUrl,
680
- disputeResolverId,
681
- queryVars
682
- );
683
- }
684
-
685
- /**
686
- * Returns dispute resolver entities from subgraph.
687
- * @param queryVars - Optional query variables to skip, order or filter.
688
- * @returns Dispute resolver entities from subgraph.
689
- */
690
- public async getDisputeResolvers(
691
- queryVars?: subgraph.GetDisputeResolversQueryQueryVariables
692
- ): Promise<subgraph.DisputeResolverFieldsFragment[]> {
693
- return accounts.subgraph.getDisputeResolvers(this._subgraphUrl, queryVars);
694
- }
695
-
696
- /* -------------------------------------------------------------------------- */
697
- /* Offer related methods */
698
- /* -------------------------------------------------------------------------- */
699
-
700
- /**
701
- * Creates offer by calling the `OfferHandlerFacet` contract.
702
- * This transaction only succeeds if there is an existing seller account for connected signer.
703
- * @param offerToCreate - Offer arguments.
704
- * @param overrides - Optional overrides.
705
- * @returns Transaction response.
706
- */
707
- public async createOffer(
708
- offerToCreate: offers.CreateOfferArgs,
709
- overrides: Partial<{
710
- contractAddress: string;
711
- }> = {}
712
- ): Promise<TransactionResponse> {
713
- return offers.handler.createOffer({
714
- offerToCreate,
715
- web3Lib: this._web3Lib,
716
- theGraphStorage: this._theGraphStorage,
717
- metadataStorage: this._metadataStorage,
718
- contractAddress: overrides.contractAddress || this._protocolDiamond
719
- });
720
- }
721
-
722
- /**
723
- * Creates a batch of offers by calling the `OfferHandlerFacet` contract.
724
- * This transaction only succeeds if there is an existing seller account for connected signer.
725
- * @param offersToCreate - Offer arguments.
726
- * @param overrides - Optional overrides.
727
- * @returns Transaction response.
728
- */
729
- public async createOfferBatch(
730
- offersToCreate: offers.CreateOfferArgs[],
731
- overrides: Partial<{
732
- contractAddress: string;
733
- }> = {}
734
- ): Promise<TransactionResponse> {
735
- return offers.handler.createOfferBatch({
736
- offersToCreate,
737
- web3Lib: this._web3Lib,
738
- theGraphStorage: this._theGraphStorage,
739
- metadataStorage: this._metadataStorage,
740
- contractAddress: overrides.contractAddress || this._protocolDiamond
741
- });
742
- }
743
-
744
- /**
745
- * Utility method to retrieve the created `offerId` from logs after calling `createOffer`
746
- * or `createOfferAndSeller`.
747
- * @param logs - Logs to search in.
748
- * @returns Created offer id.
749
- */
750
- public getCreatedOfferIdFromLogs(logs: Log[]): string | null {
751
- const offerId = getValueFromLogs({
752
- iface: offers.iface.bosonOfferHandlerIface,
753
- logs,
754
- eventArgsKey: "offerId",
755
- eventName: "OfferCreated"
756
- });
757
-
758
- return (
759
- offerId ||
760
- getValueFromLogs({
761
- iface: orchestration.iface.bosonOrchestrationHandlerIface,
762
- logs,
763
- eventArgsKey: "offerId",
764
- eventName: "OfferCreated"
765
- })
766
- );
767
- }
768
-
769
- /**
770
- * Utility method to retrieve the created `offerIds` from logs after calling `createOfferBatch`
771
- * @param logs - Logs to search in.
772
- * @returns Array of created offerIds.
773
- */
774
- public getCreatedOfferIdsFromLogs(logs: Log[]): string[] {
775
- return getValuesFromLogs({
776
- iface: offers.iface.bosonOfferHandlerIface,
777
- logs,
778
- eventArgsKey: "offerId",
779
- eventName: "OfferCreated"
780
- });
781
- }
782
-
783
- /**
784
- * Utility method to retrieve the created `groupIds` from logs after calling `createGroup`
785
- * @param logs - Logs to search in.
786
- * @returns Array of group Ids.
787
- */
788
- public getCreatedGroupIdsFromLogs(logs: Log[]): string[] {
789
- return getValuesFromLogs({
790
- iface: groups.iface.bosonGroupHandlerIface,
791
- logs,
792
- eventArgsKey: "groupId",
793
- eventName: "GroupCreated"
794
- });
795
- }
796
-
797
- /**
798
- * Utility method to retrieve the created `sellerId` from logs after calling `createSeller`
799
- * or `createOfferAndSeller`.
800
- * @param logs - Logs to search in.
801
- * @returns Created offer id.
802
- */
803
- public getCreatedSellerIdFromLogs(logs: Log[]): string | null {
804
- const sellerId = getValueFromLogs({
805
- iface: accounts.iface.bosonAccountHandlerIface,
806
- logs,
807
- eventArgsKey: "sellerId",
808
- eventName: "SellerCreated"
809
- });
810
-
811
- return (
812
- sellerId ||
813
- getValueFromLogs({
814
- iface: orchestration.iface.bosonOrchestrationHandlerIface,
815
- logs,
816
- eventArgsKey: "sellerId",
817
- eventName: "SellerCreated"
818
- })
819
- );
820
- }
821
-
822
- /**
823
- * Voids an existing offer by calling the `OfferHandlerFacet` contract.
824
- * This transaction only succeeds if the connected signer is the `operator`.
825
- * @param offerId - ID of offer to void.
826
- * @param overrides - Optional overrides.
827
- * @returns Transaction response.
828
- */
829
- public async voidOffer(
830
- offerId: BigNumberish,
831
- overrides: Partial<{
832
- contractAddress: string;
833
- }> = {}
834
- ): Promise<TransactionResponse> {
835
- return offers.handler.voidOffer({
836
- offerId,
837
- web3Lib: this._web3Lib,
838
- subgraphUrl: this._subgraphUrl,
839
- contractAddress: overrides.contractAddress || this._protocolDiamond
840
- });
841
- }
842
-
843
- /**
844
- * Voids a batch of existing offers by calling the `OfferHandlerFacet` contract.
845
- * This transaction only succeeds if the connected signer is the `operator` of all
846
- * provided offers.
847
- * @param offerIds - IDs of offers to void.
848
- * @param overrides - Optional overrides.
849
- * @returns Transaction response.
850
- */
851
- public async voidOfferBatch(
852
- offerIds: BigNumberish[],
853
- overrides: Partial<{
854
- contractAddress: string;
855
- }> = {}
856
- ): Promise<TransactionResponse> {
857
- return offers.handler.voidOfferBatch({
858
- offerIds,
859
- web3Lib: this._web3Lib,
860
- subgraphUrl: this._subgraphUrl,
861
- contractAddress: overrides.contractAddress || this._protocolDiamond
862
- });
863
- }
864
-
865
- /**
866
- * Returns offer from subgraph.
867
- * @param offerId - ID of offer.
868
- * @param queryVars - Optional query variables to skip, order or filter.
869
- * @returns Offer entity from subgraph.
870
- */
871
- public async getOfferById(
872
- offerId: BigNumberish,
873
- queryVars?: offers.subgraph.SingleOfferQueryVariables
874
- ): Promise<subgraph.OfferFieldsFragment> {
875
- return offers.subgraph.getOfferById(this._subgraphUrl, offerId, queryVars);
876
- }
877
-
878
- /**
879
- * Returns offers from subgraph.
880
- * @param queryVars - Optional query variables to skip, order or filter.
881
- * @returns Offer entities from subgraph.
882
- */
883
- public async getOffers(
884
- queryVars?: subgraph.GetOffersQueryQueryVariables
885
- ): Promise<subgraph.OfferFieldsFragment[]> {
886
- return offers.subgraph.getOffers(this._subgraphUrl, queryVars);
887
- }
888
-
889
- /**
890
- * Renders contractual agreement for given offer.
891
- * @param offerId - Id of offer to render agreement for.
892
- * @returns Contractual agreement as string.
893
- */
894
- public async renderContractualAgreementForOffer(
895
- offerId: BigNumberish
896
- ): Promise<string> {
897
- const offerData = await offers.subgraph.getOfferById(
898
- this._subgraphUrl,
899
- offerId
900
- );
901
- return offers.renderContractualAgreementForOffer(offerData);
902
- }
903
-
904
- /**
905
- * Renders contractual agreement for given offer.
906
- * @param template - Mustache syntax based template.
907
- * @param offerData - Offer data.
908
- * @returns Contractual agreement as string.
909
- */
910
- public async renderContractualAgreement(
911
- template: string,
912
- offerData: offers.CreateOfferArgs,
913
- offerMetadata: offers.AdditionalOfferMetadata
914
- ): Promise<string> {
915
- const tokenInfo = await this.getExchangeTokenInfo(offerData.exchangeToken);
916
- return offers.renderContractualAgreement(
917
- template,
918
- offerData,
919
- offerMetadata,
920
- tokenInfo
921
- );
922
- }
923
-
924
- /* -------------------------------------------------------------------------- */
925
- /* ERC20 / Exchange Token related methods */
926
- /* -------------------------------------------------------------------------- */
927
-
928
- /**
929
- * Returns the current allowance of the given token by calling the contract.
930
- * @param exchangeToken - Address of exchange token.
931
- * @param overrides - Optional overrides.
932
- * @returns Allowance for given signer.
933
- */
934
- public async getExchangeTokenAllowance(
935
- exchangeToken: string,
936
- overrides: Partial<{
937
- spender: string;
938
- owner: string;
939
- }> = {}
940
- ): Promise<string> {
941
- return erc20.handler.getAllowance({
942
- web3Lib: this._web3Lib,
943
- contractAddress: exchangeToken,
944
- spender: overrides.spender || this._protocolDiamond,
945
- owner: overrides.owner || (await this._web3Lib.getSignerAddress())
946
- });
947
- }
948
-
949
- /**
950
- * Returns `name`, `decimals` and `symbol` of the given token by calling the contract.
951
- * @param exchangeToken - Address exchange token.
952
- * @returns Decimals, name and symbol.
953
- */
954
- public async getExchangeTokenInfo(
955
- exchangeToken: string
956
- ): Promise<ITokenInfo> {
957
- if (this._tokenInfoManager === undefined) {
958
- this._tokenInfoManager = new TokenInfoManager(
959
- this._chainId,
960
- this._web3Lib,
961
- this._subgraphUrl
962
- );
963
- }
964
-
965
- return this._tokenInfoManager.getExchangeTokenInfo(exchangeToken);
966
- }
967
-
968
- /**
969
- * Approves the given amount for the main protocol contract.
970
- * @param exchangeToken - Address of token to approve.
971
- * @param value - Amount of allowance.
972
- * @param overrides - Optional overrides.
973
- * @returns Transaction response.
974
- */
975
- public async approveExchangeToken(
976
- exchangeToken: string,
977
- value: BigNumberish,
978
- overrides: Partial<{
979
- spender: string;
980
- }> = {}
981
- ): Promise<TransactionResponse> {
982
- return erc20.handler.approve({
983
- contractAddress: exchangeToken,
984
- spender: overrides.spender || this._protocolDiamond,
985
- value,
986
- web3Lib: this._web3Lib
987
- });
988
- }
989
-
990
- public async getProtocolAllowance(
991
- exchangeToken: string,
992
- overrides: Partial<{
993
- spender: string;
994
- owner: string;
995
- }> = {}
996
- ): Promise<string> {
997
- return erc20.handler.getAllowance({
998
- contractAddress: exchangeToken,
999
- owner: overrides.owner || (await this._web3Lib.getSignerAddress()),
1000
- spender: overrides.spender || this._protocolDiamond,
1001
- web3Lib: this._web3Lib
1002
- });
1003
- }
1004
-
1005
- /* -------------------------------------------------------------------------- */
1006
- /* Funds related methods */
1007
- /* -------------------------------------------------------------------------- */
1008
-
1009
- /**
1010
- * Deposit funds by calling the `FundsHandlerFacet` contract.
1011
- * @param sellerId - ID of seller account to deposit funds for.
1012
- * @param fundsAmount - Amount of funds.
1013
- * @param fundsTokenAddress - Address of funds token.
1014
- * @returns Transaction response.
1015
- */
1016
- public async depositFunds(
1017
- sellerId: BigNumberish,
1018
- fundsAmount: BigNumberish,
1019
- fundsTokenAddress: string = AddressZero
1020
- ): Promise<TransactionResponse> {
1021
- return funds.handler.depositFunds({
1022
- sellerId,
1023
- fundsAmount,
1024
- fundsTokenAddress,
1025
- contractAddress: this._protocolDiamond,
1026
- web3Lib: this._web3Lib
1027
- });
1028
- }
1029
-
1030
- /**
1031
- * Returns funds entity from subgraph.
1032
- * @param fundsId - ID of funds entity.
1033
- * @param queryVars - Optional query variables to skip, order or filter.
1034
- * @returns Funds entity from subgraph.
1035
- */
1036
- public async getFundsById(
1037
- fundsId: BigNumberish,
1038
- queryVars?: subgraph.GetFundsByIdQueryVariables
1039
- ): Promise<subgraph.FundsEntityFieldsFragment> {
1040
- return funds.subgraph.getFundsById(this._subgraphUrl, fundsId, queryVars);
1041
- }
1042
-
1043
- /**
1044
- * Returns funds entities from subgraph.
1045
- * @param queryVars - Optional query variables to skip, order or filter.
1046
- * @returns Funds entities from subgraph.
1047
- */
1048
- public async getFunds(
1049
- queryVars?: subgraph.GetFundsQueryVariables
1050
- ): Promise<subgraph.FundsEntityFieldsFragment[]> {
1051
- return funds.subgraph.getFunds(this._subgraphUrl, queryVars);
1052
- }
1053
-
1054
- /**
1055
- * Withdraw selected funds by calling the `FundsHandlerFacet` contract.
1056
- * @param sellerId - ID of seller account to withdraw funds for.
1057
- * @param tokensToWithdraw - Addresses of funds tokens to withdraw.
1058
- * @param amountsToWithdraw - Amounts of funds token to withdraw.
1059
- * @returns Transaction response.
1060
- */
1061
- public async withdrawFunds(
1062
- sellerId: BigNumberish,
1063
- tokensToWithdraw: Array<string>,
1064
- amountsToWithdraw: Array<BigNumberish>
1065
- ): Promise<TransactionResponse> {
1066
- return funds.handler.withdrawFunds({
1067
- sellerId,
1068
- tokensToWithdraw,
1069
- amountsToWithdraw,
1070
- contractAddress: this._protocolDiamond,
1071
- web3Lib: this._web3Lib
1072
- });
1073
- }
1074
-
1075
- /**
1076
- * Withdraw all available funds by calling the `FundsHandlerFacet` contract.
1077
- * @param sellerId - ID of seller account to withdraw funds for.
1078
- * @returns Transaction response.
1079
- */
1080
- public async withdrawAllAvailableFunds(
1081
- sellerId: BigNumberish
1082
- ): Promise<TransactionResponse> {
1083
- return funds.handler.withdrawAllAvailableFunds({
1084
- sellerId,
1085
- subgraphUrl: this._subgraphUrl,
1086
- contractAddress: this._protocolDiamond,
1087
- web3Lib: this._web3Lib
1088
- });
1089
- }
1090
-
1091
- /* -------------------------------------------------------------------------- */
1092
- /* Exchange related methods */
1093
- /* -------------------------------------------------------------------------- */
1094
-
1095
- /**
1096
- * Returns exchange entity from subgraph.
1097
- * @param exchangeId - ID of exchange entity.
1098
- * @param queryVars - Optional query variables to skip, order or filter.
1099
- * @returns Exchange entity from subgraph.
1100
- */
1101
- public async getExchangeById(
1102
- exchangeId: BigNumberish,
1103
- queryVars?: subgraph.GetExchangeByIdQueryQueryVariables
1104
- ): Promise<subgraph.ExchangeFieldsFragment> {
1105
- return exchanges.subgraph.getExchangeById(
1106
- this._subgraphUrl,
1107
- exchangeId,
1108
- queryVars
1109
- );
1110
- }
1111
-
1112
- /**
1113
- * Returns exchange entities from subgraph.
1114
- * @param queryVars - Optional query variables to skip, order or filter.
1115
- * @returns Exchange entities from subgraph.
1116
- */
1117
- public async getExchanges(
1118
- queryVars?: subgraph.GetExchangesQueryQueryVariables
1119
- ): Promise<subgraph.ExchangeFieldsFragment[]> {
1120
- return exchanges.subgraph.getExchanges(this._subgraphUrl, queryVars);
1121
- }
1122
-
1123
- /**
1124
- * Commits to an offer by calling the `ExchangeHandlerContract`.
1125
- * This transaction only succeeds if the seller has deposited funds.
1126
- * @param offerId - ID of offer to commit to.
1127
- * @param overrides - Optional overrides.
1128
- * @returns Transaction response.
1129
- */
1130
- public async commitToOffer(
1131
- offerId: BigNumberish,
1132
- overrides: Partial<{
1133
- buyer: string;
1134
- }> = {}
1135
- ): Promise<TransactionResponse> {
1136
- const buyer = overrides.buyer || (await this._web3Lib.getSignerAddress());
1137
- return exchanges.handler.commitToOffer({
1138
- buyer,
1139
- offerId,
1140
- web3Lib: this._web3Lib,
1141
- subgraphUrl: this._subgraphUrl,
1142
- contractAddress: this._protocolDiamond
1143
- });
1144
- }
1145
-
1146
- /**
1147
- * Utility method to retrieve the created `exchangeId` from logs after calling `commitToOffer`.
1148
- * @param logs - Logs to search in.
1149
- * @returns Created exchange id.
1150
- */
1151
- public getCommittedExchangeIdFromLogs(logs: Log[]): string | null {
1152
- return getValueFromLogs({
1153
- iface: exchanges.iface.bosonExchangeHandlerIface,
1154
- logs,
1155
- eventArgsKey: "exchangeId",
1156
- eventName: "BuyerCommitted"
1157
- });
1158
- }
1159
-
1160
- /**
1161
- * Revokes an existing voucher by calling the `ExchangeHandlerContract`.
1162
- * Callable by seller `operator`.
1163
- * @param exchangeId - ID of exchange to revoke.
1164
- * @returns Transaction response.
1165
- */
1166
- public async revokeVoucher(
1167
- exchangeId: BigNumberish
1168
- ): Promise<TransactionResponse> {
1169
- return exchanges.handler.revokeVoucher({
1170
- web3Lib: this._web3Lib,
1171
- contractAddress: this._protocolDiamond,
1172
- exchangeId,
1173
- subgraphUrl: this._subgraphUrl
1174
- });
1175
- }
1176
-
1177
- /**
1178
- * Cancels an existing voucher by calling the `ExchangeHandlerContract`.
1179
- * Callable by buyer.
1180
- * @param exchangeId - ID of exchange to cancel.
1181
- * @returns Transaction response.
1182
- */
1183
- public async cancelVoucher(
1184
- exchangeId: BigNumberish
1185
- ): Promise<TransactionResponse> {
1186
- return exchanges.handler.cancelVoucher({
1187
- web3Lib: this._web3Lib,
1188
- contractAddress: this._protocolDiamond,
1189
- exchangeId,
1190
- subgraphUrl: this._subgraphUrl
1191
- });
1192
- }
1193
-
1194
- /**
1195
- * Redeems an existing voucher by calling the `ExchangeHandlerContract`.
1196
- * Callable by buyer.
1197
- * @param exchangeId - ID of exchange to redeem.
1198
- * @returns Transaction response.
1199
- */
1200
- public async redeemVoucher(
1201
- exchangeId: BigNumberish
1202
- ): Promise<TransactionResponse> {
1203
- return exchanges.handler.redeemVoucher({
1204
- web3Lib: this._web3Lib,
1205
- contractAddress: this._protocolDiamond,
1206
- exchangeId,
1207
- subgraphUrl: this._subgraphUrl
1208
- });
1209
- }
1210
-
1211
- /**
1212
- * Completes an existing voucher by calling the `ExchangeHandlerContract`.
1213
- * Callable by buyer or seller operator.
1214
- * @param exchangeId - ID of exchange to complete.
1215
- * @returns Transaction response.
1216
- */
1217
- public async completeExchange(
1218
- exchangeId: BigNumberish
1219
- ): Promise<TransactionResponse> {
1220
- return exchanges.handler.completeExchange({
1221
- web3Lib: this._web3Lib,
1222
- contractAddress: this._protocolDiamond,
1223
- exchangeId,
1224
- subgraphUrl: this._subgraphUrl
1225
- });
1226
- }
1227
-
1228
- /**
1229
- * Completes a batch of existing vouchers by calling the `ExchangeHandlerContract`.
1230
- * Callable by buyer or seller operator.
1231
- * @param exchangeIds - IDs of exchange to complete.
1232
- * @returns Transaction response.
1233
- */
1234
- public async completeExchangeBatch(
1235
- exchangeIds: BigNumberish[]
1236
- ): Promise<TransactionResponse> {
1237
- return exchanges.handler.completeExchangeBatch({
1238
- web3Lib: this._web3Lib,
1239
- contractAddress: this._protocolDiamond,
1240
- exchangeIds,
1241
- subgraphUrl: this._subgraphUrl
1242
- });
1243
- }
1244
-
1245
- /**
1246
- * Expires an existing voucher by calling the `ExchangeHandlerContract`.
1247
- * @param exchangeId - ID of exchange to expire.
1248
- * @returns Transaction response.
1249
- */
1250
- public async expireVoucher(
1251
- exchangeId: BigNumberish
1252
- ): Promise<TransactionResponse> {
1253
- return exchanges.handler.expireVoucher({
1254
- web3Lib: this._web3Lib,
1255
- contractAddress: this._protocolDiamond,
1256
- exchangeId,
1257
- subgraphUrl: this._subgraphUrl
1258
- });
1259
- }
1260
-
1261
- /* -------------------------------------------------------------------------- */
1262
- /* Dispute related methods */
1263
- /* -------------------------------------------------------------------------- */
1264
-
1265
- /**
1266
- * Returns dispute entity from subgraph.
1267
- * @param disputeId - ID of dispute entity.
1268
- * @param queryVars - Optional query variables to skip, order or filter.
1269
- * @returns Dispute entity from subgraph.
1270
- */
1271
- public async getDisputeById(
1272
- disputeId: BigNumberish,
1273
- queryVars?: disputes.subgraph.SingleDisputeQueryVariables
1274
- ) {
1275
- return disputes.subgraph.getDisputeById(
1276
- this._subgraphUrl,
1277
- disputeId,
1278
- queryVars
1279
- );
1280
- }
1281
-
1282
- /**
1283
- * Returns dispute entities from subgraph.
1284
- * @param queryVars - Optional query variables to skip, order or filter.
1285
- * @returns Dispute entities from subgraph.
1286
- */
1287
- public async getDisputes(
1288
- queryVars?: subgraph.GetDisputesQueryQueryVariables
1289
- ) {
1290
- return disputes.subgraph.getDisputes(this._subgraphUrl, queryVars);
1291
- }
1292
-
1293
- /**
1294
- * Raises a dispute by calling the `DisputeHandlerContract`.
1295
- * @param exchangeId - ID of exchange to dispute.
1296
- * @returns Transaction response.
1297
- */
1298
- public async raiseDispute(
1299
- exchangeId: BigNumberish
1300
- ): Promise<TransactionResponse> {
1301
- return disputes.handler.raiseDispute({
1302
- exchangeId,
1303
- contractAddress: this._protocolDiamond,
1304
- web3Lib: this._web3Lib
1305
- });
1306
- }
1307
-
1308
- /**
1309
- * Retracts a dispute by calling the `DisputeHandlerContract`.
1310
- * @param exchangeId - ID of disputed exchange.
1311
- * @returns Transaction response.
1312
- */
1313
- public async retractDispute(
1314
- exchangeId: BigNumberish
1315
- ): Promise<TransactionResponse> {
1316
- return disputes.handler.retractDispute({
1317
- exchangeId,
1318
- contractAddress: this._protocolDiamond,
1319
- web3Lib: this._web3Lib
1320
- });
1321
- }
1322
-
1323
- /**
1324
- * Extends the dispute timeout by calling the `DisputeHandlerContract`.
1325
- * @param exchangeId - ID of disputed exchange.
1326
- * @param newDisputeTimeout - New dispute timeout in seconds.
1327
- * @returns Transaction response.
1328
- */
1329
- public async extendDisputeTimeout(
1330
- exchangeId: BigNumberish,
1331
- newDisputeTimeout: BigNumberish
1332
- ): Promise<TransactionResponse> {
1333
- return disputes.handler.extendDisputeTimeout({
1334
- exchangeId,
1335
- newDisputeTimeout,
1336
- contractAddress: this._protocolDiamond,
1337
- web3Lib: this._web3Lib
1338
- });
1339
- }
1340
-
1341
- /**
1342
- * Expires a dispute by calling the `DisputeHandlerContract`.
1343
- * @param exchangeId - ID of disputed exchange.
1344
- * @returns Transaction response.
1345
- */
1346
- public async expireDispute(
1347
- exchangeId: BigNumberish
1348
- ): Promise<TransactionResponse> {
1349
- return disputes.handler.expireDispute({
1350
- exchangeId,
1351
- contractAddress: this._protocolDiamond,
1352
- web3Lib: this._web3Lib
1353
- });
1354
- }
1355
-
1356
- /**
1357
- * Expires many disputes by calling the `DisputeHandlerContract`.
1358
- * @param exchangeIds - IDs of disputed exchanges.
1359
- * @returns Transaction response.
1360
- */
1361
- public async expireDisputeBatch(
1362
- exchangeIds: BigNumberish[]
1363
- ): Promise<TransactionResponse> {
1364
- return disputes.handler.expireDisputeBatch({
1365
- exchangeIds,
1366
- contractAddress: this._protocolDiamond,
1367
- web3Lib: this._web3Lib
1368
- });
1369
- }
1370
-
1371
- /**
1372
- * Resolves dispute by calling the `DisputeHandlerContract`. If caller is `buyer` then
1373
- * signature of `seller` is required as an argument. If caller if `seller` then vice-versa.
1374
- * The signature can be retrieved by calling the method
1375
- * `CoreSDK.signDisputeResolutionProposal`.
1376
- * @param args - Dispute resolve arguments:
1377
- * - `args.exchangeId` - ID of disputed exchange.
1378
- * - `args.buyerPercent` - Percentage of deposit the buyer gets.
1379
- * - `args.sigR` - r signature value of counterparty.
1380
- * - `args.sigS` - s signature value of counterparty.
1381
- * - `args.sigV` - v signature value of counterparty.
1382
- * @returns Transaction response.
1383
- */
1384
- public async resolveDispute(args: {
1385
- exchangeId: BigNumberish;
1386
- buyerPercentBasisPoints: BigNumberish;
1387
- sigR: BytesLike;
1388
- sigS: BytesLike;
1389
- sigV: BigNumberish;
1390
- }): Promise<TransactionResponse> {
1391
- return disputes.handler.resolveDispute({
1392
- ...args,
1393
- contractAddress: this._protocolDiamond,
1394
- web3Lib: this._web3Lib
1395
- });
1396
- }
1397
-
1398
- /**
1399
- * Escalates dispute by calling the `DisputeHandlerContract`.
1400
- * @param exchangeId - ID of disputed exchange.
1401
- * @returns Transaction response.
1402
- */
1403
- public async escalateDispute(
1404
- exchangeId: BigNumberish
1405
- ): Promise<TransactionResponse> {
1406
- return disputes.handler.escalateDispute({
1407
- exchangeId,
1408
- contractAddress: this._protocolDiamond,
1409
- web3Lib: this._web3Lib
1410
- });
1411
- }
1412
-
1413
- /**
1414
- * Decides dispute by calling the `DisputeHandlerContract`.
1415
- * @param exchangeId - ID of disputed exchange.
1416
- * @param buyerPercent - Percentage of deposit buyer gets.
1417
- * @returns Transaction response.
1418
- */
1419
- public async decideDispute(
1420
- exchangeId: BigNumberish,
1421
- buyerPercent: BigNumberish
1422
- ): Promise<TransactionResponse> {
1423
- return disputes.handler.decideDispute({
1424
- exchangeId,
1425
- buyerPercent,
1426
- contractAddress: this._protocolDiamond,
1427
- web3Lib: this._web3Lib
1428
- });
1429
- }
1430
-
1431
- /**
1432
- * Refuses escalated dispute by calling the `DisputeHandlerContract`.
1433
- * @param exchangeId - ID of disputed exchange.
1434
- * @returns Transaction response.
1435
- */
1436
- public async refuseEscalatedDispute(
1437
- exchangeId: BigNumberish
1438
- ): Promise<TransactionResponse> {
1439
- return disputes.handler.refuseEscalatedDispute({
1440
- exchangeId,
1441
- contractAddress: this._protocolDiamond,
1442
- web3Lib: this._web3Lib
1443
- });
1444
- }
1445
-
1446
- /**
1447
- * Expires escalated dispute by calling the `DisputeHandlerContract`.
1448
- * @param exchangeId - ID of disputed exchange.
1449
- * @returns Transaction response.
1450
- */
1451
- public async expireEscalatedDispute(
1452
- exchangeId: BigNumberish
1453
- ): Promise<TransactionResponse> {
1454
- return disputes.handler.expireEscalatedDispute({
1455
- exchangeId,
1456
- contractAddress: this._protocolDiamond,
1457
- web3Lib: this._web3Lib
1458
- });
1459
- }
1460
-
1461
- /**
1462
- * Signs dispute resolution message.
1463
- * @param args - Dispute resolve arguments:
1464
- * - `args.exchangeId` - ID of disputed exchange.
1465
- * - `args.buyerPercentBasisPoints` - Percentage of deposit the buyer gets.
1466
- * @returns Signature.
1467
- */
1468
- public async signDisputeResolutionProposal(args: {
1469
- exchangeId: BigNumberish;
1470
- buyerPercentBasisPoints: BigNumberish;
1471
- }) {
1472
- return disputes.handler.signResolutionProposal({
1473
- ...args,
1474
- web3Lib: this._web3Lib,
1475
- contractAddress: this._protocolDiamond,
1476
- chainId: this._chainId
1477
- });
1478
- }
1479
-
1480
- /* -------------------------------------------------------------------------- */
1481
- /* Meta Tx related methods */
1482
- /* -------------------------------------------------------------------------- */
1483
-
1484
- /**
1485
- * Encodes and signs a meta transaction that can be relayed.
1486
- * @param args - Meta transaction args.
1487
- * @returns Signature.
1488
- */
1489
- public async signMetaTx(
1490
- args: Omit<
1491
- Parameters<typeof metaTx.handler.signMetaTx>[0],
1492
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1493
- >
1494
- ) {
1495
- return metaTx.handler.signMetaTx({
1496
- web3Lib: this._web3Lib,
1497
- metaTxHandlerAddress: this._protocolDiamond,
1498
- chainId: this._chainId,
1499
- ...args
1500
- });
1501
- }
1502
-
1503
- /**
1504
- * Encodes and signs a meta transaction for `createSeller` that can be relayed.
1505
- * @param args - Meta transaction args.
1506
- * @returns Signature.
1507
- */
1508
- public async signMetaTxCreateSeller(
1509
- args: Omit<
1510
- Parameters<typeof metaTx.handler.signMetaTxCreateSeller>[0],
1511
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1512
- >
1513
- ) {
1514
- return metaTx.handler.signMetaTxCreateSeller({
1515
- web3Lib: this._web3Lib,
1516
- metaTxHandlerAddress: this._protocolDiamond,
1517
- chainId: this._chainId,
1518
- ...args
1519
- });
1520
- }
1521
-
1522
- /**
1523
- * Encodes and signs a meta transaction for `createOffer` that can be relayed.
1524
- * @param args - Meta transaction args.
1525
- * @returns Signature.
1526
- */
1527
- public async signMetaTxCreateOffer(
1528
- args: Omit<
1529
- Parameters<typeof metaTx.handler.signMetaTxCreateOffer>[0],
1530
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1531
- >
1532
- ) {
1533
- return metaTx.handler.signMetaTxCreateOffer({
1534
- web3Lib: this._web3Lib,
1535
- theGraphStorage: this._theGraphStorage,
1536
- metadataStorage: this._metadataStorage,
1537
- metaTxHandlerAddress: this._protocolDiamond,
1538
- chainId: this._chainId,
1539
- ...args
1540
- });
1541
- }
1542
-
1543
- /**
1544
- * Encodes and signs a meta transaction for `createOfferBatch` that can be relayed.
1545
- * @param args - Meta transaction args.
1546
- * @returns Signature.
1547
- */
1548
- public async signMetaTxCreateOfferBatch(
1549
- args: Omit<
1550
- Parameters<typeof metaTx.handler.signMetaTxCreateOfferBatch>[0],
1551
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1552
- >
1553
- ) {
1554
- return metaTx.handler.signMetaTxCreateOfferBatch({
1555
- web3Lib: this._web3Lib,
1556
- theGraphStorage: this._theGraphStorage,
1557
- metadataStorage: this._metadataStorage,
1558
- metaTxHandlerAddress: this._protocolDiamond,
1559
- chainId: this._chainId,
1560
- ...args
1561
- });
1562
- }
1563
-
1564
- /**
1565
- * Encodes and signs a meta transaction for `createGroup` that can be relayed.
1566
- * @param args - Meta transaction args.
1567
- * @returns Signature.
1568
- */
1569
- public async signMetaTxCreateGroup(
1570
- args: Omit<
1571
- Parameters<typeof metaTx.handler.signMetaTxCreateGroup>[0],
1572
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1573
- >
1574
- ) {
1575
- return metaTx.handler.signMetaTxCreateGroup({
1576
- web3Lib: this._web3Lib,
1577
- metaTxHandlerAddress: this._protocolDiamond,
1578
- chainId: this._chainId,
1579
- ...args
1580
- });
1581
- }
1582
-
1583
- /**
1584
- * Encodes and signs a meta transaction for `createOfferWithCondition` that can be relayed.
1585
- * @param args - Meta transaction args.
1586
- * @returns Signature.
1587
- */
1588
- public async signMetaTxCreateOfferWithCondition(
1589
- args: Omit<
1590
- Parameters<typeof metaTx.handler.signMetaTxCreateOfferWithCondition>[0],
1591
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1592
- >
1593
- ) {
1594
- return metaTx.handler.signMetaTxCreateOfferWithCondition({
1595
- web3Lib: this._web3Lib,
1596
- theGraphStorage: this._theGraphStorage,
1597
- metadataStorage: this._metadataStorage,
1598
- metaTxHandlerAddress: this._protocolDiamond,
1599
- chainId: this._chainId,
1600
- ...args
1601
- });
1602
- }
1603
-
1604
- /**
1605
- * Encodes and signs a meta transaction for `voidOffer` that can be relayed.
1606
- * @param args - Meta transaction args.
1607
- * @returns Signature.
1608
- */
1609
- public async signMetaTxVoidOffer(
1610
- args: Omit<
1611
- Parameters<typeof metaTx.handler.signMetaTxVoidOffer>[0],
1612
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1613
- >
1614
- ) {
1615
- return metaTx.handler.signMetaTxVoidOffer({
1616
- web3Lib: this._web3Lib,
1617
- metaTxHandlerAddress: this._protocolDiamond,
1618
- chainId: this._chainId,
1619
- ...args
1620
- });
1621
- }
1622
-
1623
- /**
1624
- * Encodes and signs a meta transaction for `voidOfferBatch` that can be relayed.
1625
- * @param args - Meta transaction args.
1626
- * @returns Signature.
1627
- */
1628
- public async signMetaTxVoidOfferBatch(
1629
- args: Omit<
1630
- Parameters<typeof metaTx.handler.signMetaTxVoidOfferBatch>[0],
1631
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1632
- >
1633
- ) {
1634
- return metaTx.handler.signMetaTxVoidOfferBatch({
1635
- web3Lib: this._web3Lib,
1636
- metaTxHandlerAddress: this._protocolDiamond,
1637
- chainId: this._chainId,
1638
- ...args
1639
- });
1640
- }
1641
-
1642
- /**
1643
- * Encodes and signs a meta transaction for `completeExchangeBatch` that can be relayed.
1644
- * @param args - Meta transaction args.
1645
- * @returns Signature.
1646
- */
1647
- public async signMetaTxCompleteExchange(
1648
- args: Omit<
1649
- Parameters<typeof metaTx.handler.signMetaTxCompleteExchange>[0],
1650
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1651
- >
1652
- ) {
1653
- return metaTx.handler.signMetaTxCompleteExchange({
1654
- web3Lib: this._web3Lib,
1655
- metaTxHandlerAddress: this._protocolDiamond,
1656
- chainId: this._chainId,
1657
- ...args
1658
- });
1659
- }
1660
-
1661
- /**
1662
- * Encodes and signs a meta transaction for `completeExchangeBatch` that can be relayed.
1663
- * @param args - Meta transaction args.
1664
- * @returns Signature.
1665
- */
1666
- public async signMetaTxCompleteExchangeBatch(
1667
- args: Omit<
1668
- Parameters<typeof metaTx.handler.signMetaTxCompleteExchangeBatch>[0],
1669
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1670
- >
1671
- ) {
1672
- return metaTx.handler.signMetaTxCompleteExchangeBatch({
1673
- web3Lib: this._web3Lib,
1674
- metaTxHandlerAddress: this._protocolDiamond,
1675
- chainId: this._chainId,
1676
- ...args
1677
- });
1678
- }
1679
-
1680
- /**
1681
- * Encodes and signs a meta transaction for `commitToOffer` that can be relayed.
1682
- * @param args - Meta transaction args.
1683
- * @returns Signature.
1684
- */
1685
- public async signMetaTxCommitToOffer(
1686
- args: Omit<
1687
- Parameters<typeof metaTx.handler.signMetaTxCommitToOffer>[0],
1688
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1689
- >
1690
- ) {
1691
- return metaTx.handler.signMetaTxCommitToOffer({
1692
- web3Lib: this._web3Lib,
1693
- metaTxHandlerAddress: this._protocolDiamond,
1694
- chainId: this._chainId,
1695
- ...args
1696
- });
1697
- }
1698
-
1699
- /**
1700
- * Encodes and signs a meta transaction for `cancelVoucher` that can be relayed.
1701
- * @param args - Meta transaction args.
1702
- * @returns Signature.
1703
- */
1704
- public async signMetaTxCancelVoucher(
1705
- args: Omit<
1706
- Parameters<typeof metaTx.handler.signMetaTxCancelVoucher>[0],
1707
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1708
- >
1709
- ) {
1710
- return metaTx.handler.signMetaTxCancelVoucher({
1711
- web3Lib: this._web3Lib,
1712
- metaTxHandlerAddress: this._protocolDiamond,
1713
- chainId: this._chainId,
1714
- ...args
1715
- });
1716
- }
1717
-
1718
- /**
1719
- * Encodes and signs a meta transaction for `redeemVoucher` that can be relayed.
1720
- * @param args - Meta transaction args.
1721
- * @returns Signature.
1722
- */
1723
- public async signMetaTxRedeemVoucher(
1724
- args: Omit<
1725
- Parameters<typeof metaTx.handler.signMetaTxRedeemVoucher>[0],
1726
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1727
- >
1728
- ) {
1729
- return metaTx.handler.signMetaTxRedeemVoucher({
1730
- web3Lib: this._web3Lib,
1731
- metaTxHandlerAddress: this._protocolDiamond,
1732
- chainId: this._chainId,
1733
- ...args
1734
- });
1735
- }
1736
-
1737
- /**
1738
- * Encodes and signs a meta transaction for `expireVoucher` that can be relayed.
1739
- * @param args - Meta transaction args.
1740
- * @returns Signature.
1741
- */
1742
- public async signMetaTxExpireVoucher(
1743
- args: Omit<
1744
- Parameters<typeof metaTx.handler.signMetaTxExpireVoucher>[0],
1745
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1746
- >
1747
- ) {
1748
- return metaTx.handler.signMetaTxExpireVoucher({
1749
- web3Lib: this._web3Lib,
1750
- metaTxHandlerAddress: this._protocolDiamond,
1751
- chainId: this._chainId,
1752
- ...args
1753
- });
1754
- }
1755
-
1756
- /**
1757
- * Encodes and signs a meta transaction for `revokeVoucher` that can be relayed.
1758
- * @param args - Meta transaction args.
1759
- * @returns Signature.
1760
- */
1761
- public async signMetaTxRevokeVoucher(
1762
- args: Omit<
1763
- Parameters<typeof metaTx.handler.signMetaTxRevokeVoucher>[0],
1764
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1765
- >
1766
- ) {
1767
- return metaTx.handler.signMetaTxRevokeVoucher({
1768
- web3Lib: this._web3Lib,
1769
- metaTxHandlerAddress: this._protocolDiamond,
1770
- chainId: this._chainId,
1771
- ...args
1772
- });
1773
- }
1774
-
1775
- /**
1776
- * Encodes and signs a meta transaction for `retractDispute` that can be relayed.
1777
- * @param args - Meta transaction args.
1778
- * @returns Signature.
1779
- */
1780
- public async signMetaTxRetractDispute(
1781
- args: Omit<
1782
- Parameters<typeof metaTx.handler.signMetaTxRetractDispute>[0],
1783
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1784
- >
1785
- ) {
1786
- return metaTx.handler.signMetaTxRetractDispute({
1787
- web3Lib: this._web3Lib,
1788
- metaTxHandlerAddress: this._protocolDiamond,
1789
- chainId: this._chainId,
1790
- ...args
1791
- });
1792
- }
1793
-
1794
- /**
1795
- * Encodes and signs a meta transaction for `escalateDispute` that can be relayed.
1796
- * @param args - Meta transaction args.
1797
- * @returns Signature.
1798
- */
1799
- public async signMetaTxEscalateDispute(
1800
- args: Omit<
1801
- Parameters<typeof metaTx.handler.signMetaTxEscalateDispute>[0],
1802
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1803
- >
1804
- ) {
1805
- return metaTx.handler.signMetaTxEscalateDispute({
1806
- web3Lib: this._web3Lib,
1807
- metaTxHandlerAddress: this._protocolDiamond,
1808
- chainId: this._chainId,
1809
- ...args
1810
- });
1811
- }
1812
-
1813
- /**
1814
- * Encodes and signs a meta transaction for `raiseDispute` that can be relayed.
1815
- * @param args - Meta transaction args.
1816
- * @returns Signature.
1817
- */
1818
- public async signMetaTxRaiseDispute(
1819
- args: Omit<
1820
- Parameters<typeof metaTx.handler.signMetaTxRaiseDispute>[0],
1821
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1822
- >
1823
- ) {
1824
- return metaTx.handler.signMetaTxRaiseDispute({
1825
- web3Lib: this._web3Lib,
1826
- metaTxHandlerAddress: this._protocolDiamond,
1827
- chainId: this._chainId,
1828
- ...args
1829
- });
1830
- }
1831
-
1832
- /**
1833
- * Encodes and signs a meta transaction for `resolveDispute` that can be relayed.
1834
- * @param args - Meta transaction args.
1835
- * @returns Signature.
1836
- */
1837
- public async signMetaTxResolveDispute(
1838
- args: Omit<
1839
- Parameters<typeof metaTx.handler.signMetaTxResolveDispute>[0],
1840
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1841
- >
1842
- ) {
1843
- return metaTx.handler.signMetaTxResolveDispute({
1844
- web3Lib: this._web3Lib,
1845
- metaTxHandlerAddress: this._protocolDiamond,
1846
- chainId: this._chainId,
1847
- ...args
1848
- });
1849
- }
1850
-
1851
- /**
1852
- * Encodes and signs a meta transaction for `extendDisputeTimeout` that can be relayed.
1853
- * @param args - Meta transaction args.
1854
- * @returns Signature.
1855
- */
1856
- public async signMetaTxExtendDisputeTimeout(
1857
- args: Omit<
1858
- Parameters<typeof metaTx.handler.signMetaTxExtendDisputeTimeout>[0],
1859
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1860
- >
1861
- ) {
1862
- return metaTx.handler.signMetaTxExtendDisputeTimeout({
1863
- web3Lib: this._web3Lib,
1864
- metaTxHandlerAddress: this._protocolDiamond,
1865
- chainId: this._chainId,
1866
- ...args
1867
- });
1868
- }
1869
-
1870
- /**
1871
- * Encodes and signs a meta transaction for `withdrawFunds` that can be relayed.
1872
- * @param args - Meta transaction args.
1873
- * @returns Signature.
1874
- */
1875
- public async signMetaTxWithdrawFunds(
1876
- args: Omit<
1877
- Parameters<typeof metaTx.handler.signMetaTxWithdrawFunds>[0],
1878
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1879
- >
1880
- ) {
1881
- return metaTx.handler.signMetaTxWithdrawFunds({
1882
- web3Lib: this._web3Lib,
1883
- metaTxHandlerAddress: this._protocolDiamond,
1884
- chainId: this._chainId,
1885
- ...args
1886
- });
1887
- }
1888
-
1889
- /**
1890
- * Encodes and signs a meta transaction for `depositFunds` that can be relayed.
1891
- * @param args - Meta transaction args.
1892
- * @returns Signature.
1893
- */
1894
- public async signMetaTxDepositFunds(
1895
- args: Omit<
1896
- Parameters<typeof metaTx.handler.signMetaTxDepositFunds>[0],
1897
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1898
- >
1899
- ) {
1900
- return metaTx.handler.signMetaTxDepositFunds({
1901
- web3Lib: this._web3Lib,
1902
- metaTxHandlerAddress: this._protocolDiamond,
1903
- chainId: this._chainId,
1904
- ...args
1905
- });
1906
- }
1907
-
1908
- /**
1909
- * Relay a meta transaction,
1910
- * @param metaTxParams - Required params for meta transaction.
1911
- * @param overrides - Optional overrides.
1912
- * @returns Transaction response.
1913
- */
1914
- public async relayMetaTransaction(
1915
- metaTxParams: {
1916
- functionName: string;
1917
- functionSignature: BytesLike;
1918
- nonce: BigNumberish;
1919
- sigR: BytesLike;
1920
- sigS: BytesLike;
1921
- sigV: BigNumberish;
1922
- },
1923
- overrides: Partial<{
1924
- userAddress: string;
1925
- contractAddress: string;
1926
- metaTxConfig: Partial<Omit<MetaTxConfig, "apiIds"> & { apiId: string }>;
1927
- metaTransactionMethod: string;
1928
- }> = {}
1929
- ): Promise<TransactionResponse> {
1930
- const { metaTxApiId, metaTxApiKey, metaTxRelayerUrl, contractAddress } =
1931
- this.assertAndGetMetaTxConfig(overrides);
1932
-
1933
- return metaTx.handler.relayMetaTransaction({
1934
- web3LibAdapter: this._web3Lib,
1935
- contractAddress,
1936
- chainId: this._chainId,
1937
- metaTx: {
1938
- config: {
1939
- relayerUrl: metaTxRelayerUrl,
1940
- apiId: metaTxApiId,
1941
- apiKey: metaTxApiKey
1942
- },
1943
- params: {
1944
- userAddress:
1945
- overrides.userAddress || (await this._web3Lib.getSignerAddress()),
1946
- functionName: metaTxParams.functionName,
1947
- functionSignature: metaTxParams.functionSignature,
1948
- nonce: metaTxParams.nonce,
1949
- sigR: metaTxParams.sigR,
1950
- sigS: metaTxParams.sigS,
1951
- sigV: metaTxParams.sigV
1952
- }
1953
- }
1954
- });
1955
- }
1956
-
1957
- /**
1958
- * Encodes and signs a native "token.approve()" meta transaction that can be relayed.
1959
- * @param exchangeToken - The address of the token contract.
1960
- * @param value - The value to be approved.
1961
- * @param overrides - Optionally specify a spender address (default is the protocol contract address).
1962
- * @returns Signature.
1963
- */
1964
- public async signNativeMetaTxApproveExchangeToken(
1965
- exchangeToken: string,
1966
- value: BigNumberish,
1967
- overrides: Partial<{
1968
- spender: string;
1969
- }> = {}
1970
- ) {
1971
- const user = await this._web3Lib.getSignerAddress();
1972
- return nativeMetaTx.handler.signNativeMetaTxApproveExchangeToken({
1973
- web3Lib: this._web3Lib,
1974
- chainId: this._chainId,
1975
- user,
1976
- exchangeToken,
1977
- spender: overrides.spender || this._protocolDiamond,
1978
- value
1979
- });
1980
- }
1981
-
1982
- /**
1983
- * Relay a native meta transaction,
1984
- * @param metaTxParams - Required params for meta transaction.
1985
- * @param overrides - Optional overrides.
1986
- * @returns Transaction response.
1987
- */
1988
- public async relayNativeMetaTransaction(
1989
- contractAddress: string,
1990
- metaTxParams: {
1991
- functionSignature: BytesLike;
1992
- sigR: BytesLike;
1993
- sigS: BytesLike;
1994
- sigV: BigNumberish;
1995
- },
1996
- overrides: Partial<{
1997
- userAddress: string;
1998
- metaTxConfig: Partial<Omit<MetaTxConfig, "apiIds"> & { apiId: string }>;
1999
- metaTransactionMethod: string;
2000
- }> = {}
2001
- ): Promise<TransactionResponse> {
2002
- const { metaTxApiId, metaTxApiKey, metaTxRelayerUrl } =
2003
- this.assertAndGetMetaTxConfig({ ...overrides, contractAddress });
2004
-
2005
- return nativeMetaTx.handler.relayNativeMetaTransaction({
2006
- web3LibAdapter: this._web3Lib,
2007
- contractAddress,
2008
- chainId: this._chainId,
2009
- metaTx: {
2010
- config: {
2011
- relayerUrl: metaTxRelayerUrl,
2012
- apiId: metaTxApiId,
2013
- apiKey: metaTxApiKey
2014
- },
2015
- params: {
2016
- userAddress:
2017
- overrides.userAddress || (await this._web3Lib.getSignerAddress()),
2018
- functionSignature: metaTxParams.functionSignature,
2019
- sigR: metaTxParams.sigR,
2020
- sigS: metaTxParams.sigS,
2021
- sigV: metaTxParams.sigV
2022
- }
2023
- }
2024
- });
2025
- }
2026
-
2027
- /**
2028
- * Returns information of submitted meta transaction.
2029
- * See https://docs.biconomy.io/api/native-meta-tx/get-retried-hashes.
2030
- * @param originalMetaTxHash - Original meta transaction as returned by `coreSDK.relayMetaTransaction`
2031
- * @param overrides - Optional overrides for meta transaction config.
2032
- * @returns - Additional meta transaction information.
2033
- */
2034
- public async getResubmittedMetaTx(
2035
- originalMetaTxHash: string,
2036
- overrides: Partial<{
2037
- contractAddress: string;
2038
- metaTxConfig: Partial<Omit<MetaTxConfig, "apiIds"> & { apiId: string }>;
2039
- metaTransactionMethod: string;
2040
- }> = {}
2041
- ): Promise<GetRetriedHashesData> {
2042
- const { metaTxApiId, metaTxApiKey, metaTxRelayerUrl } =
2043
- this.assertAndGetMetaTxConfig(overrides);
2044
-
2045
- return metaTx.handler.getResubmitted({
2046
- chainId: this._chainId,
2047
- metaTx: {
2048
- config: {
2049
- relayerUrl: metaTxRelayerUrl,
2050
- apiId: metaTxApiId,
2051
- apiKey: metaTxApiKey
2052
- },
2053
- originalHash: originalMetaTxHash
2054
- }
2055
- });
2056
- }
2057
-
2058
- private assertAndGetMetaTxConfig(
2059
- overrides: Partial<{
2060
- contractAddress: string;
2061
- metaTxConfig: Partial<Omit<MetaTxConfig, "apiIds"> & { apiId: string }>;
2062
- metaTransactionMethod: string;
2063
- }> = {}
2064
- ) {
2065
- const contractAddress = overrides.contractAddress || this._protocolDiamond;
2066
- const metaTransactionMethod =
2067
- overrides.metaTransactionMethod || "executeMetaTransaction";
2068
- const metaTxRelayerUrl =
2069
- overrides.metaTxConfig?.relayerUrl || this._metaTxConfig?.relayerUrl;
2070
- const metaTxApiKey =
2071
- overrides.metaTxConfig?.apiKey || this._metaTxConfig?.apiKey;
2072
- // metaTxApiId is depending on the contract/method(=executeMetaTransaction) to be called with Biconomy
2073
- const apiIds = this._metaTxConfig?.apiIds[contractAddress.toLowerCase()];
2074
- const metaTxApiId =
2075
- overrides.metaTxConfig?.apiId ||
2076
- (apiIds && apiIds[metaTransactionMethod]);
2077
-
2078
- if (!(metaTxRelayerUrl && metaTxApiKey && metaTxApiId)) {
2079
- throw new Error(
2080
- "CoreSDK not configured to relay meta transactions. Either pass in 'relayerUrl', 'apiKey' and 'apiId' during initialization OR as overrides arguments."
2081
- );
2082
- }
2083
-
2084
- return {
2085
- metaTxRelayerUrl,
2086
- metaTxApiId,
2087
- metaTxApiKey,
2088
- contractAddress
2089
- };
2090
- }
2091
-
2092
- /* -------------------------------------------------------------------------- */
2093
- /* Event logs */
2094
- /* -------------------------------------------------------------------------- */
2095
-
2096
- /**
2097
- * Returns event logs from subgraph.
2098
- * @param queryVars - Optional query variables to skip, order or filter.
2099
- * @returns Event log entities from subgraph.
2100
- */
2101
- public async getEventLogs(
2102
- queryVars?: subgraph.GetEventLogsQueryQueryVariables
2103
- ) {
2104
- return eventLogs.subgraph.getEventLogs(this._subgraphUrl, queryVars);
2105
- }
2106
-
2107
- /* -------------------------------------------------------------------------- */
2108
- /* Groups */
2109
- /* -------------------------------------------------------------------------- */
2110
-
2111
- /**
2112
- * Creates a group of contract addresses
2113
- * @param groupToCreate - group with the contract condition
2114
- * @param overrides - Optional overrides.
2115
- * @returns Transaction response.
2116
- */
2117
- public async createGroup(
2118
- groupToCreate: CreateGroupArgs,
2119
- overrides: Partial<{
2120
- contractAddress: string;
2121
- }> = {}
2122
- ): Promise<TransactionResponse> {
2123
- return groups.handler.createGroup({
2124
- groupToCreate,
2125
- contractAddress: overrides.contractAddress || this._protocolDiamond,
2126
- web3Lib: this._web3Lib
2127
- });
2128
- }
2129
-
2130
- /**
2131
- * Creates an offer with a specific conditions
2132
- * @param offerToCreate - Offer arguments.
2133
- * @param condition - contract condition applied to the offer
2134
- * @param overrides - Optional overrides.
2135
- * @returns Transaction response.
2136
- */
2137
- public async createOfferWithCondition(
2138
- offerToCreate: offers.CreateOfferArgs,
2139
- condition: ConditionStruct,
2140
- overrides: Partial<{
2141
- contractAddress: string;
2142
- }> = {}
2143
- ): Promise<TransactionResponse> {
2144
- return orchestration.handler.createOfferWithCondition({
2145
- offerToCreate,
2146
- contractAddress: overrides.contractAddress || this._protocolDiamond,
2147
- web3Lib: this._web3Lib,
2148
- metadataStorage: this._metadataStorage,
2149
- theGraphStorage: this._theGraphStorage,
2150
- condition
2151
- });
2152
- }
2153
- /**
2154
- * Creates a seller account and offer with a specific conditions
2155
- * This transaction only succeeds if there is no existing seller account for the connected signer.
2156
- * @param sellerToCreate - Addresses to set in the seller account.
2157
- * @param offerToCreate - Offer arguments.
2158
- * @param condition - contract condition applied to the offer
2159
- * @param overrides - Optional overrides.
2160
- * @returns Transaction response.
2161
- */
2162
- public async createSellerAndOfferWithCondition(
2163
- sellerToCreate: accounts.CreateSellerArgs,
2164
- offerToCreate: offers.CreateOfferArgs,
2165
- condition: ConditionStruct,
2166
- overrides: Partial<{
2167
- contractAddress: string;
2168
- }> = {}
2169
- ): Promise<TransactionResponse> {
2170
- return orchestration.handler.createSellerAndOfferWithCondition({
2171
- sellerToCreate,
2172
- offerToCreate,
2173
- contractAddress: overrides.contractAddress || this._protocolDiamond,
2174
- web3Lib: this._web3Lib,
2175
- metadataStorage: this._metadataStorage,
2176
- theGraphStorage: this._theGraphStorage,
2177
- condition
2178
- });
2179
- }
2180
- }
93
+ // Doc: https://www.typescriptlang.org/docs/handbook/mixins.html#alternative-pattern
94
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
95
+ export interface CoreSDK
96
+ extends MetadataMixin,
97
+ AccountsMixin,
98
+ OfferMixin,
99
+ FundsMixin,
100
+ ExchangesMixin,
101
+ DisputesMixin,
102
+ MetaTxMixin,
103
+ NativeMetaTxMixin,
104
+ GroupsMixin,
105
+ OrchestrationMixin,
106
+ EventLogsMixin {}
107
+ applyMixins(CoreSDK, [
108
+ MetadataMixin,
109
+ AccountsMixin,
110
+ OfferMixin,
111
+ FundsMixin,
112
+ ExchangesMixin,
113
+ DisputesMixin,
114
+ MetaTxMixin,
115
+ NativeMetaTxMixin,
116
+ GroupsMixin,
117
+ OrchestrationMixin,
118
+ EventLogsMixin
119
+ ]);