@bosonprotocol/core-sdk 1.23.0-alpha.2 → 1.23.0-alpha.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) 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/erc1155/handler.d.ts +9 -0
  14. package/dist/cjs/erc1155/handler.d.ts.map +1 -0
  15. package/dist/cjs/erc1155/handler.js +28 -0
  16. package/dist/cjs/erc1155/handler.js.map +1 -0
  17. package/dist/cjs/erc1155/index.d.ts +3 -0
  18. package/dist/cjs/erc1155/index.d.ts.map +1 -0
  19. package/dist/cjs/erc1155/index.js +29 -0
  20. package/dist/cjs/erc1155/index.js.map +1 -0
  21. package/dist/cjs/erc1155/interface.d.ts +3 -0
  22. package/dist/cjs/erc1155/interface.d.ts.map +1 -0
  23. package/dist/cjs/erc1155/interface.js +7 -0
  24. package/dist/cjs/erc1155/interface.js.map +1 -0
  25. package/dist/cjs/erc20/handler.d.ts +5 -0
  26. package/dist/cjs/erc20/handler.d.ts.map +1 -1
  27. package/dist/cjs/erc20/handler.js +12 -1
  28. package/dist/cjs/erc20/handler.js.map +1 -1
  29. package/dist/cjs/erc721/handler.d.ts +5 -0
  30. package/dist/cjs/erc721/handler.d.ts.map +1 -1
  31. package/dist/cjs/erc721/handler.js +12 -1
  32. package/dist/cjs/erc721/handler.js.map +1 -1
  33. package/dist/cjs/event-logs/mixin.d.ts +11 -0
  34. package/dist/cjs/event-logs/mixin.d.ts.map +1 -0
  35. package/dist/cjs/event-logs/mixin.js +28 -0
  36. package/dist/cjs/event-logs/mixin.js.map +1 -0
  37. package/dist/cjs/exchanges/mixin.d.ts +77 -0
  38. package/dist/cjs/exchanges/mixin.d.ts.map +1 -0
  39. package/dist/cjs/exchanges/mixin.js +172 -0
  40. package/dist/cjs/exchanges/mixin.js.map +1 -0
  41. package/dist/cjs/funds/mixin.d.ts +42 -0
  42. package/dist/cjs/funds/mixin.d.ts.map +1 -0
  43. package/dist/cjs/funds/mixin.js +95 -0
  44. package/dist/cjs/funds/mixin.js.map +1 -0
  45. package/dist/cjs/groups/mixin.d.ts +14 -0
  46. package/dist/cjs/groups/mixin.d.ts.map +1 -0
  47. package/dist/cjs/groups/mixin.js +33 -0
  48. package/dist/cjs/groups/mixin.js.map +1 -0
  49. package/dist/cjs/meta-tx/mixin.d.ts +176 -0
  50. package/dist/cjs/meta-tx/mixin.d.ts.map +1 -0
  51. package/dist/cjs/meta-tx/mixin.js +296 -0
  52. package/dist/cjs/meta-tx/mixin.js.map +1 -0
  53. package/dist/cjs/metadata/mixin.d.ts +42 -0
  54. package/dist/cjs/metadata/mixin.d.ts.map +1 -0
  55. package/dist/cjs/metadata/mixin.js +89 -0
  56. package/dist/cjs/metadata/mixin.js.map +1 -0
  57. package/dist/cjs/metadata/subgraph.d.ts +3 -1
  58. package/dist/cjs/metadata/subgraph.d.ts.map +1 -1
  59. package/dist/cjs/metadata/subgraph.js +17 -1
  60. package/dist/cjs/metadata/subgraph.js.map +1 -1
  61. package/dist/cjs/mixins/base-core-sdk.d.ts +41 -0
  62. package/dist/cjs/mixins/base-core-sdk.d.ts.map +1 -0
  63. package/dist/cjs/mixins/base-core-sdk.js +51 -0
  64. package/dist/cjs/mixins/base-core-sdk.js.map +1 -0
  65. package/dist/cjs/native-meta-tx/mixin.d.ts +35 -0
  66. package/dist/cjs/native-meta-tx/mixin.d.ts.map +1 -0
  67. package/dist/cjs/native-meta-tx/mixin.js +68 -0
  68. package/dist/cjs/native-meta-tx/mixin.js.map +1 -0
  69. package/dist/cjs/offers/mixin.d.ts +133 -0
  70. package/dist/cjs/offers/mixin.d.ts.map +1 -0
  71. package/dist/cjs/offers/mixin.js +338 -0
  72. package/dist/cjs/offers/mixin.js.map +1 -0
  73. package/dist/cjs/orchestration/mixin.d.ts +28 -0
  74. package/dist/cjs/orchestration/mixin.d.ts.map +1 -0
  75. package/dist/cjs/orchestration/mixin.js +59 -0
  76. package/dist/cjs/orchestration/mixin.js.map +1 -0
  77. package/dist/cjs/subgraph.d.ts +3707 -1509
  78. package/dist/cjs/subgraph.d.ts.map +1 -1
  79. package/dist/cjs/subgraph.js +113 -4
  80. package/dist/cjs/subgraph.js.map +1 -1
  81. package/dist/cjs/utils/graphql.d.ts +14 -0
  82. package/dist/cjs/utils/graphql.d.ts.map +1 -1
  83. package/dist/cjs/utils/signature.d.ts.map +1 -1
  84. package/dist/cjs/utils/signature.js +5 -1
  85. package/dist/cjs/utils/signature.js.map +1 -1
  86. package/dist/cjs/utils/tokenInfoManager.d.ts +6 -2
  87. package/dist/cjs/utils/tokenInfoManager.d.ts.map +1 -1
  88. package/dist/cjs/utils/tokenInfoManager.js +39 -6
  89. package/dist/cjs/utils/tokenInfoManager.js.map +1 -1
  90. package/dist/esm/accounts/mixin.d.ts +194 -0
  91. package/dist/esm/accounts/mixin.d.ts.map +1 -0
  92. package/dist/esm/accounts/mixin.js +342 -0
  93. package/dist/esm/accounts/mixin.js.map +1 -0
  94. package/dist/esm/core-sdk.d.ts +16 -818
  95. package/dist/esm/core-sdk.d.ts.map +1 -1
  96. package/dist/esm/core-sdk.js +27 -1483
  97. package/dist/esm/core-sdk.js.map +1 -1
  98. package/dist/esm/disputes/mixin.d.ts +113 -0
  99. package/dist/esm/disputes/mixin.d.ts.map +1 -0
  100. package/dist/esm/disputes/mixin.js +173 -0
  101. package/dist/esm/disputes/mixin.js.map +1 -0
  102. package/dist/esm/erc1155/handler.d.ts +9 -0
  103. package/dist/esm/erc1155/handler.d.ts.map +1 -0
  104. package/dist/esm/erc1155/handler.js +13 -0
  105. package/dist/esm/erc1155/handler.js.map +1 -0
  106. package/dist/esm/erc1155/index.d.ts +3 -0
  107. package/dist/esm/erc1155/index.d.ts.map +1 -0
  108. package/dist/esm/erc1155/index.js +3 -0
  109. package/dist/esm/erc1155/index.js.map +1 -0
  110. package/dist/esm/erc1155/interface.d.ts +3 -0
  111. package/dist/esm/erc1155/interface.d.ts.map +1 -0
  112. package/dist/esm/erc1155/interface.js +4 -0
  113. package/dist/esm/erc1155/interface.js.map +1 -0
  114. package/dist/esm/erc20/handler.d.ts +5 -0
  115. package/dist/esm/erc20/handler.d.ts.map +1 -1
  116. package/dist/esm/erc20/handler.js +8 -0
  117. package/dist/esm/erc20/handler.js.map +1 -1
  118. package/dist/esm/erc721/handler.d.ts +5 -0
  119. package/dist/esm/erc721/handler.d.ts.map +1 -1
  120. package/dist/esm/erc721/handler.js +8 -0
  121. package/dist/esm/erc721/handler.js.map +1 -1
  122. package/dist/esm/event-logs/mixin.d.ts +11 -0
  123. package/dist/esm/event-logs/mixin.d.ts.map +1 -0
  124. package/dist/esm/event-logs/mixin.js +13 -0
  125. package/dist/esm/event-logs/mixin.js.map +1 -0
  126. package/dist/esm/exchanges/mixin.d.ts +77 -0
  127. package/dist/esm/exchanges/mixin.d.ts.map +1 -0
  128. package/dist/esm/exchanges/mixin.js +141 -0
  129. package/dist/esm/exchanges/mixin.js.map +1 -0
  130. package/dist/esm/funds/mixin.d.ts +42 -0
  131. package/dist/esm/funds/mixin.d.ts.map +1 -0
  132. package/dist/esm/funds/mixin.js +72 -0
  133. package/dist/esm/funds/mixin.js.map +1 -0
  134. package/dist/esm/groups/mixin.d.ts +14 -0
  135. package/dist/esm/groups/mixin.d.ts.map +1 -0
  136. package/dist/esm/groups/mixin.js +18 -0
  137. package/dist/esm/groups/mixin.js.map +1 -0
  138. package/dist/esm/meta-tx/mixin.d.ts +176 -0
  139. package/dist/esm/meta-tx/mixin.d.ts.map +1 -0
  140. package/dist/esm/meta-tx/mixin.js +351 -0
  141. package/dist/esm/meta-tx/mixin.js.map +1 -0
  142. package/dist/esm/metadata/mixin.d.ts +42 -0
  143. package/dist/esm/metadata/mixin.d.ts.map +1 -0
  144. package/dist/esm/metadata/mixin.js +60 -0
  145. package/dist/esm/metadata/mixin.js.map +1 -0
  146. package/dist/esm/metadata/subgraph.d.ts +3 -1
  147. package/dist/esm/metadata/subgraph.d.ts.map +1 -1
  148. package/dist/esm/metadata/subgraph.js +14 -0
  149. package/dist/esm/metadata/subgraph.js.map +1 -1
  150. package/dist/esm/mixins/base-core-sdk.d.ts +41 -0
  151. package/dist/esm/mixins/base-core-sdk.d.ts.map +1 -0
  152. package/dist/esm/mixins/base-core-sdk.js +54 -0
  153. package/dist/esm/mixins/base-core-sdk.js.map +1 -0
  154. package/dist/esm/native-meta-tx/mixin.d.ts +35 -0
  155. package/dist/esm/native-meta-tx/mixin.d.ts.map +1 -0
  156. package/dist/esm/native-meta-tx/mixin.js +51 -0
  157. package/dist/esm/native-meta-tx/mixin.js.map +1 -0
  158. package/dist/esm/offers/mixin.d.ts +133 -0
  159. package/dist/esm/offers/mixin.d.ts.map +1 -0
  160. package/dist/esm/offers/mixin.js +276 -0
  161. package/dist/esm/offers/mixin.js.map +1 -0
  162. package/dist/esm/orchestration/mixin.d.ts +28 -0
  163. package/dist/esm/orchestration/mixin.d.ts.map +1 -0
  164. package/dist/esm/orchestration/mixin.js +42 -0
  165. package/dist/esm/orchestration/mixin.js.map +1 -0
  166. package/dist/esm/subgraph.d.ts +3707 -1509
  167. package/dist/esm/subgraph.d.ts.map +1 -1
  168. package/dist/esm/subgraph.js +110 -1
  169. package/dist/esm/subgraph.js.map +1 -1
  170. package/dist/esm/utils/graphql.d.ts +14 -0
  171. package/dist/esm/utils/graphql.d.ts.map +1 -1
  172. package/dist/esm/utils/signature.d.ts.map +1 -1
  173. package/dist/esm/utils/signature.js +5 -1
  174. package/dist/esm/utils/signature.js.map +1 -1
  175. package/dist/esm/utils/tokenInfoManager.d.ts +6 -2
  176. package/dist/esm/utils/tokenInfoManager.d.ts.map +1 -1
  177. package/dist/esm/utils/tokenInfoManager.js +39 -6
  178. package/dist/esm/utils/tokenInfoManager.js.map +1 -1
  179. package/package.json +3 -3
  180. package/src/accounts/mixin.ts +484 -0
  181. package/src/core-sdk.ts +42 -2102
  182. package/src/disputes/mixin.ts +240 -0
  183. package/src/erc1155/handler.ts +21 -0
  184. package/src/erc1155/index.ts +2 -0
  185. package/src/erc1155/interface.ts +4 -0
  186. package/src/erc20/handler.ts +14 -0
  187. package/src/erc721/handler.ts +14 -0
  188. package/src/event-logs/mixin.ts +16 -0
  189. package/src/exchanges/mixin.ts +184 -0
  190. package/src/funds/mixin.ts +99 -0
  191. package/src/groups/mixin.ts +24 -0
  192. package/src/meta-tx/mixin.ts +515 -0
  193. package/src/metadata/mixin.ts +97 -0
  194. package/src/metadata/product-v1.graphql +77 -1
  195. package/src/metadata/subgraph.ts +31 -1
  196. package/src/mixins/base-core-sdk.ts +96 -0
  197. package/src/native-meta-tx/mixin.ts +77 -0
  198. package/src/offers/mixin.ts +376 -0
  199. package/src/offers/queries.graphql +1 -1
  200. package/src/orchestration/mixin.ts +57 -0
  201. package/src/subgraph.ts +3620 -1296
  202. package/src/utils/signature.ts +6 -1
  203. package/src/utils/tokenInfoManager.ts +44 -6
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,2040 +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
- );
962
- }
963
-
964
- return this._tokenInfoManager.getExchangeTokenInfo(exchangeToken);
965
- }
966
-
967
- /**
968
- * Approves the given amount for the main protocol contract.
969
- * @param exchangeToken - Address of token to approve.
970
- * @param value - Amount of allowance.
971
- * @param overrides - Optional overrides.
972
- * @returns Transaction response.
973
- */
974
- public async approveExchangeToken(
975
- exchangeToken: string,
976
- value: BigNumberish,
977
- overrides: Partial<{
978
- spender: string;
979
- }> = {}
980
- ): Promise<TransactionResponse> {
981
- return erc20.handler.approve({
982
- contractAddress: exchangeToken,
983
- spender: overrides.spender || this._protocolDiamond,
984
- value,
985
- web3Lib: this._web3Lib
986
- });
987
- }
988
-
989
- public async getProtocolAllowance(
990
- exchangeToken: string,
991
- overrides: Partial<{
992
- spender: string;
993
- owner: string;
994
- }> = {}
995
- ): Promise<string> {
996
- return erc20.handler.getAllowance({
997
- contractAddress: exchangeToken,
998
- owner: overrides.owner || (await this._web3Lib.getSignerAddress()),
999
- spender: overrides.spender || this._protocolDiamond,
1000
- web3Lib: this._web3Lib
1001
- });
1002
- }
1003
-
1004
- /* -------------------------------------------------------------------------- */
1005
- /* Funds related methods */
1006
- /* -------------------------------------------------------------------------- */
1007
-
1008
- /**
1009
- * Deposit funds by calling the `FundsHandlerFacet` contract.
1010
- * @param sellerId - ID of seller account to deposit funds for.
1011
- * @param fundsAmount - Amount of funds.
1012
- * @param fundsTokenAddress - Address of funds token.
1013
- * @returns Transaction response.
1014
- */
1015
- public async depositFunds(
1016
- sellerId: BigNumberish,
1017
- fundsAmount: BigNumberish,
1018
- fundsTokenAddress: string = AddressZero
1019
- ): Promise<TransactionResponse> {
1020
- return funds.handler.depositFunds({
1021
- sellerId,
1022
- fundsAmount,
1023
- fundsTokenAddress,
1024
- contractAddress: this._protocolDiamond,
1025
- web3Lib: this._web3Lib
1026
- });
1027
- }
1028
-
1029
- /**
1030
- * Returns funds entity from subgraph.
1031
- * @param fundsId - ID of funds entity.
1032
- * @param queryVars - Optional query variables to skip, order or filter.
1033
- * @returns Funds entity from subgraph.
1034
- */
1035
- public async getFundsById(
1036
- fundsId: BigNumberish,
1037
- queryVars?: subgraph.GetFundsByIdQueryVariables
1038
- ): Promise<subgraph.FundsEntityFieldsFragment> {
1039
- return funds.subgraph.getFundsById(this._subgraphUrl, fundsId, queryVars);
1040
- }
1041
-
1042
- /**
1043
- * Returns funds entities from subgraph.
1044
- * @param queryVars - Optional query variables to skip, order or filter.
1045
- * @returns Funds entities from subgraph.
1046
- */
1047
- public async getFunds(
1048
- queryVars?: subgraph.GetFundsQueryVariables
1049
- ): Promise<subgraph.FundsEntityFieldsFragment[]> {
1050
- return funds.subgraph.getFunds(this._subgraphUrl, queryVars);
1051
- }
1052
-
1053
- /**
1054
- * Withdraw selected funds by calling the `FundsHandlerFacet` contract.
1055
- * @param sellerId - ID of seller account to withdraw funds for.
1056
- * @param tokensToWithdraw - Addresses of funds tokens to withdraw.
1057
- * @param amountsToWithdraw - Amounts of funds token to withdraw.
1058
- * @returns Transaction response.
1059
- */
1060
- public async withdrawFunds(
1061
- sellerId: BigNumberish,
1062
- tokensToWithdraw: Array<string>,
1063
- amountsToWithdraw: Array<BigNumberish>
1064
- ): Promise<TransactionResponse> {
1065
- return funds.handler.withdrawFunds({
1066
- sellerId,
1067
- tokensToWithdraw,
1068
- amountsToWithdraw,
1069
- contractAddress: this._protocolDiamond,
1070
- web3Lib: this._web3Lib
1071
- });
1072
- }
1073
-
1074
- /**
1075
- * Withdraw all available funds by calling the `FundsHandlerFacet` contract.
1076
- * @param sellerId - ID of seller account to withdraw funds for.
1077
- * @returns Transaction response.
1078
- */
1079
- public async withdrawAllAvailableFunds(
1080
- sellerId: BigNumberish
1081
- ): Promise<TransactionResponse> {
1082
- return funds.handler.withdrawAllAvailableFunds({
1083
- sellerId,
1084
- subgraphUrl: this._subgraphUrl,
1085
- contractAddress: this._protocolDiamond,
1086
- web3Lib: this._web3Lib
1087
- });
1088
- }
1089
-
1090
- /* -------------------------------------------------------------------------- */
1091
- /* Exchange related methods */
1092
- /* -------------------------------------------------------------------------- */
1093
-
1094
- /**
1095
- * Returns exchange entity from subgraph.
1096
- * @param exchangeId - ID of exchange entity.
1097
- * @param queryVars - Optional query variables to skip, order or filter.
1098
- * @returns Exchange entity from subgraph.
1099
- */
1100
- public async getExchangeById(
1101
- exchangeId: BigNumberish,
1102
- queryVars?: subgraph.GetExchangeByIdQueryQueryVariables
1103
- ): Promise<subgraph.ExchangeFieldsFragment> {
1104
- return exchanges.subgraph.getExchangeById(
1105
- this._subgraphUrl,
1106
- exchangeId,
1107
- queryVars
1108
- );
1109
- }
1110
-
1111
- /**
1112
- * Returns exchange entities from subgraph.
1113
- * @param queryVars - Optional query variables to skip, order or filter.
1114
- * @returns Exchange entities from subgraph.
1115
- */
1116
- public async getExchanges(
1117
- queryVars?: subgraph.GetExchangesQueryQueryVariables
1118
- ): Promise<subgraph.ExchangeFieldsFragment[]> {
1119
- return exchanges.subgraph.getExchanges(this._subgraphUrl, queryVars);
1120
- }
1121
-
1122
- /**
1123
- * Commits to an offer by calling the `ExchangeHandlerContract`.
1124
- * This transaction only succeeds if the seller has deposited funds.
1125
- * @param offerId - ID of offer to commit to.
1126
- * @param overrides - Optional overrides.
1127
- * @returns Transaction response.
1128
- */
1129
- public async commitToOffer(
1130
- offerId: BigNumberish,
1131
- overrides: Partial<{
1132
- buyer: string;
1133
- }> = {}
1134
- ): Promise<TransactionResponse> {
1135
- const buyer = overrides.buyer || (await this._web3Lib.getSignerAddress());
1136
- return exchanges.handler.commitToOffer({
1137
- buyer,
1138
- offerId,
1139
- web3Lib: this._web3Lib,
1140
- subgraphUrl: this._subgraphUrl,
1141
- contractAddress: this._protocolDiamond
1142
- });
1143
- }
1144
-
1145
- /**
1146
- * Utility method to retrieve the created `exchangeId` from logs after calling `commitToOffer`.
1147
- * @param logs - Logs to search in.
1148
- * @returns Created exchange id.
1149
- */
1150
- public getCommittedExchangeIdFromLogs(logs: Log[]): string | null {
1151
- return getValueFromLogs({
1152
- iface: exchanges.iface.bosonExchangeHandlerIface,
1153
- logs,
1154
- eventArgsKey: "exchangeId",
1155
- eventName: "BuyerCommitted"
1156
- });
1157
- }
1158
-
1159
- /**
1160
- * Revokes an existing voucher by calling the `ExchangeHandlerContract`.
1161
- * Callable by seller `operator`.
1162
- * @param exchangeId - ID of exchange to revoke.
1163
- * @returns Transaction response.
1164
- */
1165
- public async revokeVoucher(
1166
- exchangeId: BigNumberish
1167
- ): Promise<TransactionResponse> {
1168
- return exchanges.handler.revokeVoucher({
1169
- web3Lib: this._web3Lib,
1170
- contractAddress: this._protocolDiamond,
1171
- exchangeId,
1172
- subgraphUrl: this._subgraphUrl
1173
- });
1174
- }
1175
-
1176
- /**
1177
- * Cancels an existing voucher by calling the `ExchangeHandlerContract`.
1178
- * Callable by buyer.
1179
- * @param exchangeId - ID of exchange to cancel.
1180
- * @returns Transaction response.
1181
- */
1182
- public async cancelVoucher(
1183
- exchangeId: BigNumberish
1184
- ): Promise<TransactionResponse> {
1185
- return exchanges.handler.cancelVoucher({
1186
- web3Lib: this._web3Lib,
1187
- contractAddress: this._protocolDiamond,
1188
- exchangeId,
1189
- subgraphUrl: this._subgraphUrl
1190
- });
1191
- }
1192
-
1193
- /**
1194
- * Redeems an existing voucher by calling the `ExchangeHandlerContract`.
1195
- * Callable by buyer.
1196
- * @param exchangeId - ID of exchange to redeem.
1197
- * @returns Transaction response.
1198
- */
1199
- public async redeemVoucher(
1200
- exchangeId: BigNumberish
1201
- ): Promise<TransactionResponse> {
1202
- return exchanges.handler.redeemVoucher({
1203
- web3Lib: this._web3Lib,
1204
- contractAddress: this._protocolDiamond,
1205
- exchangeId,
1206
- subgraphUrl: this._subgraphUrl
1207
- });
1208
- }
1209
-
1210
- /**
1211
- * Completes an existing voucher by calling the `ExchangeHandlerContract`.
1212
- * Callable by buyer or seller operator.
1213
- * @param exchangeId - ID of exchange to complete.
1214
- * @returns Transaction response.
1215
- */
1216
- public async completeExchange(
1217
- exchangeId: BigNumberish
1218
- ): Promise<TransactionResponse> {
1219
- return exchanges.handler.completeExchange({
1220
- web3Lib: this._web3Lib,
1221
- contractAddress: this._protocolDiamond,
1222
- exchangeId,
1223
- subgraphUrl: this._subgraphUrl
1224
- });
1225
- }
1226
-
1227
- /**
1228
- * Completes a batch of existing vouchers by calling the `ExchangeHandlerContract`.
1229
- * Callable by buyer or seller operator.
1230
- * @param exchangeIds - IDs of exchange to complete.
1231
- * @returns Transaction response.
1232
- */
1233
- public async completeExchangeBatch(
1234
- exchangeIds: BigNumberish[]
1235
- ): Promise<TransactionResponse> {
1236
- return exchanges.handler.completeExchangeBatch({
1237
- web3Lib: this._web3Lib,
1238
- contractAddress: this._protocolDiamond,
1239
- exchangeIds,
1240
- subgraphUrl: this._subgraphUrl
1241
- });
1242
- }
1243
-
1244
- /**
1245
- * Expires an existing voucher by calling the `ExchangeHandlerContract`.
1246
- * @param exchangeId - ID of exchange to expire.
1247
- * @returns Transaction response.
1248
- */
1249
- public async expireVoucher(
1250
- exchangeId: BigNumberish
1251
- ): Promise<TransactionResponse> {
1252
- return exchanges.handler.expireVoucher({
1253
- web3Lib: this._web3Lib,
1254
- contractAddress: this._protocolDiamond,
1255
- exchangeId,
1256
- subgraphUrl: this._subgraphUrl
1257
- });
1258
- }
1259
-
1260
- /* -------------------------------------------------------------------------- */
1261
- /* Dispute related methods */
1262
- /* -------------------------------------------------------------------------- */
1263
-
1264
- /**
1265
- * Returns dispute entity from subgraph.
1266
- * @param disputeId - ID of dispute entity.
1267
- * @param queryVars - Optional query variables to skip, order or filter.
1268
- * @returns Dispute entity from subgraph.
1269
- */
1270
- public async getDisputeById(
1271
- disputeId: BigNumberish,
1272
- queryVars?: disputes.subgraph.SingleDisputeQueryVariables
1273
- ) {
1274
- return disputes.subgraph.getDisputeById(
1275
- this._subgraphUrl,
1276
- disputeId,
1277
- queryVars
1278
- );
1279
- }
1280
-
1281
- /**
1282
- * Returns dispute entities from subgraph.
1283
- * @param queryVars - Optional query variables to skip, order or filter.
1284
- * @returns Dispute entities from subgraph.
1285
- */
1286
- public async getDisputes(
1287
- queryVars?: subgraph.GetDisputesQueryQueryVariables
1288
- ) {
1289
- return disputes.subgraph.getDisputes(this._subgraphUrl, queryVars);
1290
- }
1291
-
1292
- /**
1293
- * Raises a dispute by calling the `DisputeHandlerContract`.
1294
- * @param exchangeId - ID of exchange to dispute.
1295
- * @returns Transaction response.
1296
- */
1297
- public async raiseDispute(
1298
- exchangeId: BigNumberish
1299
- ): Promise<TransactionResponse> {
1300
- return disputes.handler.raiseDispute({
1301
- exchangeId,
1302
- contractAddress: this._protocolDiamond,
1303
- web3Lib: this._web3Lib
1304
- });
1305
- }
1306
-
1307
- /**
1308
- * Retracts a dispute by calling the `DisputeHandlerContract`.
1309
- * @param exchangeId - ID of disputed exchange.
1310
- * @returns Transaction response.
1311
- */
1312
- public async retractDispute(
1313
- exchangeId: BigNumberish
1314
- ): Promise<TransactionResponse> {
1315
- return disputes.handler.retractDispute({
1316
- exchangeId,
1317
- contractAddress: this._protocolDiamond,
1318
- web3Lib: this._web3Lib
1319
- });
1320
- }
1321
-
1322
- /**
1323
- * Extends the dispute timeout by calling the `DisputeHandlerContract`.
1324
- * @param exchangeId - ID of disputed exchange.
1325
- * @param newDisputeTimeout - New dispute timeout in seconds.
1326
- * @returns Transaction response.
1327
- */
1328
- public async extendDisputeTimeout(
1329
- exchangeId: BigNumberish,
1330
- newDisputeTimeout: BigNumberish
1331
- ): Promise<TransactionResponse> {
1332
- return disputes.handler.extendDisputeTimeout({
1333
- exchangeId,
1334
- newDisputeTimeout,
1335
- contractAddress: this._protocolDiamond,
1336
- web3Lib: this._web3Lib
1337
- });
1338
- }
1339
-
1340
- /**
1341
- * Expires a dispute by calling the `DisputeHandlerContract`.
1342
- * @param exchangeId - ID of disputed exchange.
1343
- * @returns Transaction response.
1344
- */
1345
- public async expireDispute(
1346
- exchangeId: BigNumberish
1347
- ): Promise<TransactionResponse> {
1348
- return disputes.handler.expireDispute({
1349
- exchangeId,
1350
- contractAddress: this._protocolDiamond,
1351
- web3Lib: this._web3Lib
1352
- });
1353
- }
1354
-
1355
- /**
1356
- * Expires many disputes by calling the `DisputeHandlerContract`.
1357
- * @param exchangeIds - IDs of disputed exchanges.
1358
- * @returns Transaction response.
1359
- */
1360
- public async expireDisputeBatch(
1361
- exchangeIds: BigNumberish[]
1362
- ): Promise<TransactionResponse> {
1363
- return disputes.handler.expireDisputeBatch({
1364
- exchangeIds,
1365
- contractAddress: this._protocolDiamond,
1366
- web3Lib: this._web3Lib
1367
- });
1368
- }
1369
-
1370
- /**
1371
- * Resolves dispute by calling the `DisputeHandlerContract`. If caller is `buyer` then
1372
- * signature of `seller` is required as an argument. If caller if `seller` then vice-versa.
1373
- * The signature can be retrieved by calling the method
1374
- * `CoreSDK.signDisputeResolutionProposal`.
1375
- * @param args - Dispute resolve arguments:
1376
- * - `args.exchangeId` - ID of disputed exchange.
1377
- * - `args.buyerPercent` - Percentage of deposit the buyer gets.
1378
- * - `args.sigR` - r signature value of counterparty.
1379
- * - `args.sigS` - s signature value of counterparty.
1380
- * - `args.sigV` - v signature value of counterparty.
1381
- * @returns Transaction response.
1382
- */
1383
- public async resolveDispute(args: {
1384
- exchangeId: BigNumberish;
1385
- buyerPercentBasisPoints: BigNumberish;
1386
- sigR: BytesLike;
1387
- sigS: BytesLike;
1388
- sigV: BigNumberish;
1389
- }): Promise<TransactionResponse> {
1390
- return disputes.handler.resolveDispute({
1391
- ...args,
1392
- contractAddress: this._protocolDiamond,
1393
- web3Lib: this._web3Lib
1394
- });
1395
- }
1396
-
1397
- /**
1398
- * Escalates dispute by calling the `DisputeHandlerContract`.
1399
- * @param exchangeId - ID of disputed exchange.
1400
- * @returns Transaction response.
1401
- */
1402
- public async escalateDispute(
1403
- exchangeId: BigNumberish
1404
- ): Promise<TransactionResponse> {
1405
- return disputes.handler.escalateDispute({
1406
- exchangeId,
1407
- contractAddress: this._protocolDiamond,
1408
- web3Lib: this._web3Lib
1409
- });
1410
- }
1411
-
1412
- /**
1413
- * Decides dispute by calling the `DisputeHandlerContract`.
1414
- * @param exchangeId - ID of disputed exchange.
1415
- * @param buyerPercent - Percentage of deposit buyer gets.
1416
- * @returns Transaction response.
1417
- */
1418
- public async decideDispute(
1419
- exchangeId: BigNumberish,
1420
- buyerPercent: BigNumberish
1421
- ): Promise<TransactionResponse> {
1422
- return disputes.handler.decideDispute({
1423
- exchangeId,
1424
- buyerPercent,
1425
- contractAddress: this._protocolDiamond,
1426
- web3Lib: this._web3Lib
1427
- });
1428
- }
1429
-
1430
- /**
1431
- * Refuses escalated dispute by calling the `DisputeHandlerContract`.
1432
- * @param exchangeId - ID of disputed exchange.
1433
- * @returns Transaction response.
1434
- */
1435
- public async refuseEscalatedDispute(
1436
- exchangeId: BigNumberish
1437
- ): Promise<TransactionResponse> {
1438
- return disputes.handler.refuseEscalatedDispute({
1439
- exchangeId,
1440
- contractAddress: this._protocolDiamond,
1441
- web3Lib: this._web3Lib
1442
- });
1443
- }
1444
-
1445
- /**
1446
- * Expires escalated dispute by calling the `DisputeHandlerContract`.
1447
- * @param exchangeId - ID of disputed exchange.
1448
- * @returns Transaction response.
1449
- */
1450
- public async expireEscalatedDispute(
1451
- exchangeId: BigNumberish
1452
- ): Promise<TransactionResponse> {
1453
- return disputes.handler.expireEscalatedDispute({
1454
- exchangeId,
1455
- contractAddress: this._protocolDiamond,
1456
- web3Lib: this._web3Lib
1457
- });
1458
- }
1459
-
1460
- /**
1461
- * Signs dispute resolution message.
1462
- * @param args - Dispute resolve arguments:
1463
- * - `args.exchangeId` - ID of disputed exchange.
1464
- * - `args.buyerPercentBasisPoints` - Percentage of deposit the buyer gets.
1465
- * @returns Signature.
1466
- */
1467
- public async signDisputeResolutionProposal(args: {
1468
- exchangeId: BigNumberish;
1469
- buyerPercentBasisPoints: BigNumberish;
1470
- }) {
1471
- return disputes.handler.signResolutionProposal({
1472
- ...args,
1473
- web3Lib: this._web3Lib,
1474
- contractAddress: this._protocolDiamond,
1475
- chainId: this._chainId
1476
- });
1477
- }
1478
-
1479
- /* -------------------------------------------------------------------------- */
1480
- /* Meta Tx related methods */
1481
- /* -------------------------------------------------------------------------- */
1482
-
1483
- /**
1484
- * Encodes and signs a meta transaction that can be relayed.
1485
- * @param args - Meta transaction args.
1486
- * @returns Signature.
1487
- */
1488
- public async signMetaTx(
1489
- args: Omit<
1490
- Parameters<typeof metaTx.handler.signMetaTx>[0],
1491
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1492
- >
1493
- ) {
1494
- return metaTx.handler.signMetaTx({
1495
- web3Lib: this._web3Lib,
1496
- metaTxHandlerAddress: this._protocolDiamond,
1497
- chainId: this._chainId,
1498
- ...args
1499
- });
1500
- }
1501
-
1502
- /**
1503
- * Encodes and signs a meta transaction for `createSeller` that can be relayed.
1504
- * @param args - Meta transaction args.
1505
- * @returns Signature.
1506
- */
1507
- public async signMetaTxCreateSeller(
1508
- args: Omit<
1509
- Parameters<typeof metaTx.handler.signMetaTxCreateSeller>[0],
1510
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1511
- >
1512
- ) {
1513
- return metaTx.handler.signMetaTxCreateSeller({
1514
- web3Lib: this._web3Lib,
1515
- metaTxHandlerAddress: this._protocolDiamond,
1516
- chainId: this._chainId,
1517
- ...args
1518
- });
1519
- }
1520
-
1521
- /**
1522
- * Encodes and signs a meta transaction for `createOffer` that can be relayed.
1523
- * @param args - Meta transaction args.
1524
- * @returns Signature.
1525
- */
1526
- public async signMetaTxCreateOffer(
1527
- args: Omit<
1528
- Parameters<typeof metaTx.handler.signMetaTxCreateOffer>[0],
1529
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1530
- >
1531
- ) {
1532
- return metaTx.handler.signMetaTxCreateOffer({
1533
- web3Lib: this._web3Lib,
1534
- theGraphStorage: this._theGraphStorage,
1535
- metadataStorage: this._metadataStorage,
1536
- metaTxHandlerAddress: this._protocolDiamond,
1537
- chainId: this._chainId,
1538
- ...args
1539
- });
1540
- }
1541
-
1542
- /**
1543
- * Encodes and signs a meta transaction for `createOfferBatch` that can be relayed.
1544
- * @param args - Meta transaction args.
1545
- * @returns Signature.
1546
- */
1547
- public async signMetaTxCreateOfferBatch(
1548
- args: Omit<
1549
- Parameters<typeof metaTx.handler.signMetaTxCreateOfferBatch>[0],
1550
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1551
- >
1552
- ) {
1553
- return metaTx.handler.signMetaTxCreateOfferBatch({
1554
- web3Lib: this._web3Lib,
1555
- theGraphStorage: this._theGraphStorage,
1556
- metadataStorage: this._metadataStorage,
1557
- metaTxHandlerAddress: this._protocolDiamond,
1558
- chainId: this._chainId,
1559
- ...args
1560
- });
1561
- }
1562
-
1563
- /**
1564
- * Encodes and signs a meta transaction for `createGroup` that can be relayed.
1565
- * @param args - Meta transaction args.
1566
- * @returns Signature.
1567
- */
1568
- public async signMetaTxCreateGroup(
1569
- args: Omit<
1570
- Parameters<typeof metaTx.handler.signMetaTxCreateGroup>[0],
1571
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1572
- >
1573
- ) {
1574
- return metaTx.handler.signMetaTxCreateGroup({
1575
- web3Lib: this._web3Lib,
1576
- metaTxHandlerAddress: this._protocolDiamond,
1577
- chainId: this._chainId,
1578
- ...args
1579
- });
1580
- }
1581
-
1582
- /**
1583
- * Encodes and signs a meta transaction for `createOfferWithCondition` that can be relayed.
1584
- * @param args - Meta transaction args.
1585
- * @returns Signature.
1586
- */
1587
- public async signMetaTxCreateOfferWithCondition(
1588
- args: Omit<
1589
- Parameters<typeof metaTx.handler.signMetaTxCreateOfferWithCondition>[0],
1590
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1591
- >
1592
- ) {
1593
- return metaTx.handler.signMetaTxCreateOfferWithCondition({
1594
- web3Lib: this._web3Lib,
1595
- theGraphStorage: this._theGraphStorage,
1596
- metadataStorage: this._metadataStorage,
1597
- metaTxHandlerAddress: this._protocolDiamond,
1598
- chainId: this._chainId,
1599
- ...args
1600
- });
1601
- }
1602
-
1603
- /**
1604
- * Encodes and signs a meta transaction for `voidOffer` that can be relayed.
1605
- * @param args - Meta transaction args.
1606
- * @returns Signature.
1607
- */
1608
- public async signMetaTxVoidOffer(
1609
- args: Omit<
1610
- Parameters<typeof metaTx.handler.signMetaTxVoidOffer>[0],
1611
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1612
- >
1613
- ) {
1614
- return metaTx.handler.signMetaTxVoidOffer({
1615
- web3Lib: this._web3Lib,
1616
- metaTxHandlerAddress: this._protocolDiamond,
1617
- chainId: this._chainId,
1618
- ...args
1619
- });
1620
- }
1621
-
1622
- /**
1623
- * Encodes and signs a meta transaction for `voidOfferBatch` that can be relayed.
1624
- * @param args - Meta transaction args.
1625
- * @returns Signature.
1626
- */
1627
- public async signMetaTxVoidOfferBatch(
1628
- args: Omit<
1629
- Parameters<typeof metaTx.handler.signMetaTxVoidOfferBatch>[0],
1630
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1631
- >
1632
- ) {
1633
- return metaTx.handler.signMetaTxVoidOfferBatch({
1634
- web3Lib: this._web3Lib,
1635
- metaTxHandlerAddress: this._protocolDiamond,
1636
- chainId: this._chainId,
1637
- ...args
1638
- });
1639
- }
1640
-
1641
- /**
1642
- * Encodes and signs a meta transaction for `completeExchangeBatch` that can be relayed.
1643
- * @param args - Meta transaction args.
1644
- * @returns Signature.
1645
- */
1646
- public async signMetaTxCompleteExchange(
1647
- args: Omit<
1648
- Parameters<typeof metaTx.handler.signMetaTxCompleteExchange>[0],
1649
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1650
- >
1651
- ) {
1652
- return metaTx.handler.signMetaTxCompleteExchange({
1653
- web3Lib: this._web3Lib,
1654
- metaTxHandlerAddress: this._protocolDiamond,
1655
- chainId: this._chainId,
1656
- ...args
1657
- });
1658
- }
1659
-
1660
- /**
1661
- * Encodes and signs a meta transaction for `completeExchangeBatch` that can be relayed.
1662
- * @param args - Meta transaction args.
1663
- * @returns Signature.
1664
- */
1665
- public async signMetaTxCompleteExchangeBatch(
1666
- args: Omit<
1667
- Parameters<typeof metaTx.handler.signMetaTxCompleteExchangeBatch>[0],
1668
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1669
- >
1670
- ) {
1671
- return metaTx.handler.signMetaTxCompleteExchangeBatch({
1672
- web3Lib: this._web3Lib,
1673
- metaTxHandlerAddress: this._protocolDiamond,
1674
- chainId: this._chainId,
1675
- ...args
1676
- });
1677
- }
1678
-
1679
- /**
1680
- * Encodes and signs a meta transaction for `commitToOffer` that can be relayed.
1681
- * @param args - Meta transaction args.
1682
- * @returns Signature.
1683
- */
1684
- public async signMetaTxCommitToOffer(
1685
- args: Omit<
1686
- Parameters<typeof metaTx.handler.signMetaTxCommitToOffer>[0],
1687
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1688
- >
1689
- ) {
1690
- return metaTx.handler.signMetaTxCommitToOffer({
1691
- web3Lib: this._web3Lib,
1692
- metaTxHandlerAddress: this._protocolDiamond,
1693
- chainId: this._chainId,
1694
- ...args
1695
- });
1696
- }
1697
-
1698
- /**
1699
- * Encodes and signs a meta transaction for `cancelVoucher` that can be relayed.
1700
- * @param args - Meta transaction args.
1701
- * @returns Signature.
1702
- */
1703
- public async signMetaTxCancelVoucher(
1704
- args: Omit<
1705
- Parameters<typeof metaTx.handler.signMetaTxCancelVoucher>[0],
1706
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1707
- >
1708
- ) {
1709
- return metaTx.handler.signMetaTxCancelVoucher({
1710
- web3Lib: this._web3Lib,
1711
- metaTxHandlerAddress: this._protocolDiamond,
1712
- chainId: this._chainId,
1713
- ...args
1714
- });
1715
- }
1716
-
1717
- /**
1718
- * Encodes and signs a meta transaction for `redeemVoucher` that can be relayed.
1719
- * @param args - Meta transaction args.
1720
- * @returns Signature.
1721
- */
1722
- public async signMetaTxRedeemVoucher(
1723
- args: Omit<
1724
- Parameters<typeof metaTx.handler.signMetaTxRedeemVoucher>[0],
1725
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1726
- >
1727
- ) {
1728
- return metaTx.handler.signMetaTxRedeemVoucher({
1729
- web3Lib: this._web3Lib,
1730
- metaTxHandlerAddress: this._protocolDiamond,
1731
- chainId: this._chainId,
1732
- ...args
1733
- });
1734
- }
1735
-
1736
- /**
1737
- * Encodes and signs a meta transaction for `expireVoucher` that can be relayed.
1738
- * @param args - Meta transaction args.
1739
- * @returns Signature.
1740
- */
1741
- public async signMetaTxExpireVoucher(
1742
- args: Omit<
1743
- Parameters<typeof metaTx.handler.signMetaTxExpireVoucher>[0],
1744
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1745
- >
1746
- ) {
1747
- return metaTx.handler.signMetaTxExpireVoucher({
1748
- web3Lib: this._web3Lib,
1749
- metaTxHandlerAddress: this._protocolDiamond,
1750
- chainId: this._chainId,
1751
- ...args
1752
- });
1753
- }
1754
-
1755
- /**
1756
- * Encodes and signs a meta transaction for `revokeVoucher` that can be relayed.
1757
- * @param args - Meta transaction args.
1758
- * @returns Signature.
1759
- */
1760
- public async signMetaTxRevokeVoucher(
1761
- args: Omit<
1762
- Parameters<typeof metaTx.handler.signMetaTxRevokeVoucher>[0],
1763
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1764
- >
1765
- ) {
1766
- return metaTx.handler.signMetaTxRevokeVoucher({
1767
- web3Lib: this._web3Lib,
1768
- metaTxHandlerAddress: this._protocolDiamond,
1769
- chainId: this._chainId,
1770
- ...args
1771
- });
1772
- }
1773
-
1774
- /**
1775
- * Encodes and signs a meta transaction for `retractDispute` that can be relayed.
1776
- * @param args - Meta transaction args.
1777
- * @returns Signature.
1778
- */
1779
- public async signMetaTxRetractDispute(
1780
- args: Omit<
1781
- Parameters<typeof metaTx.handler.signMetaTxRetractDispute>[0],
1782
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1783
- >
1784
- ) {
1785
- return metaTx.handler.signMetaTxRetractDispute({
1786
- web3Lib: this._web3Lib,
1787
- metaTxHandlerAddress: this._protocolDiamond,
1788
- chainId: this._chainId,
1789
- ...args
1790
- });
1791
- }
1792
-
1793
- /**
1794
- * Encodes and signs a meta transaction for `escalateDispute` that can be relayed.
1795
- * @param args - Meta transaction args.
1796
- * @returns Signature.
1797
- */
1798
- public async signMetaTxEscalateDispute(
1799
- args: Omit<
1800
- Parameters<typeof metaTx.handler.signMetaTxEscalateDispute>[0],
1801
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1802
- >
1803
- ) {
1804
- return metaTx.handler.signMetaTxEscalateDispute({
1805
- web3Lib: this._web3Lib,
1806
- metaTxHandlerAddress: this._protocolDiamond,
1807
- chainId: this._chainId,
1808
- ...args
1809
- });
1810
- }
1811
-
1812
- /**
1813
- * Encodes and signs a meta transaction for `raiseDispute` that can be relayed.
1814
- * @param args - Meta transaction args.
1815
- * @returns Signature.
1816
- */
1817
- public async signMetaTxRaiseDispute(
1818
- args: Omit<
1819
- Parameters<typeof metaTx.handler.signMetaTxRaiseDispute>[0],
1820
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1821
- >
1822
- ) {
1823
- return metaTx.handler.signMetaTxRaiseDispute({
1824
- web3Lib: this._web3Lib,
1825
- metaTxHandlerAddress: this._protocolDiamond,
1826
- chainId: this._chainId,
1827
- ...args
1828
- });
1829
- }
1830
-
1831
- /**
1832
- * Encodes and signs a meta transaction for `resolveDispute` that can be relayed.
1833
- * @param args - Meta transaction args.
1834
- * @returns Signature.
1835
- */
1836
- public async signMetaTxResolveDispute(
1837
- args: Omit<
1838
- Parameters<typeof metaTx.handler.signMetaTxResolveDispute>[0],
1839
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1840
- >
1841
- ) {
1842
- return metaTx.handler.signMetaTxResolveDispute({
1843
- web3Lib: this._web3Lib,
1844
- metaTxHandlerAddress: this._protocolDiamond,
1845
- chainId: this._chainId,
1846
- ...args
1847
- });
1848
- }
1849
-
1850
- /**
1851
- * Encodes and signs a meta transaction for `extendDisputeTimeout` that can be relayed.
1852
- * @param args - Meta transaction args.
1853
- * @returns Signature.
1854
- */
1855
- public async signMetaTxExtendDisputeTimeout(
1856
- args: Omit<
1857
- Parameters<typeof metaTx.handler.signMetaTxExtendDisputeTimeout>[0],
1858
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1859
- >
1860
- ) {
1861
- return metaTx.handler.signMetaTxExtendDisputeTimeout({
1862
- web3Lib: this._web3Lib,
1863
- metaTxHandlerAddress: this._protocolDiamond,
1864
- chainId: this._chainId,
1865
- ...args
1866
- });
1867
- }
1868
-
1869
- /**
1870
- * Encodes and signs a meta transaction for `withdrawFunds` that can be relayed.
1871
- * @param args - Meta transaction args.
1872
- * @returns Signature.
1873
- */
1874
- public async signMetaTxWithdrawFunds(
1875
- args: Omit<
1876
- Parameters<typeof metaTx.handler.signMetaTxWithdrawFunds>[0],
1877
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1878
- >
1879
- ) {
1880
- return metaTx.handler.signMetaTxWithdrawFunds({
1881
- web3Lib: this._web3Lib,
1882
- metaTxHandlerAddress: this._protocolDiamond,
1883
- chainId: this._chainId,
1884
- ...args
1885
- });
1886
- }
1887
-
1888
- /**
1889
- * Encodes and signs a meta transaction for `depositFunds` that can be relayed.
1890
- * @param args - Meta transaction args.
1891
- * @returns Signature.
1892
- */
1893
- public async signMetaTxDepositFunds(
1894
- args: Omit<
1895
- Parameters<typeof metaTx.handler.signMetaTxDepositFunds>[0],
1896
- "web3Lib" | "metaTxHandlerAddress" | "chainId"
1897
- >
1898
- ) {
1899
- return metaTx.handler.signMetaTxDepositFunds({
1900
- web3Lib: this._web3Lib,
1901
- metaTxHandlerAddress: this._protocolDiamond,
1902
- chainId: this._chainId,
1903
- ...args
1904
- });
1905
- }
1906
-
1907
- /**
1908
- * Relay a meta transaction,
1909
- * @param metaTxParams - Required params for meta transaction.
1910
- * @param overrides - Optional overrides.
1911
- * @returns Transaction response.
1912
- */
1913
- public async relayMetaTransaction(
1914
- metaTxParams: {
1915
- functionName: string;
1916
- functionSignature: BytesLike;
1917
- nonce: BigNumberish;
1918
- sigR: BytesLike;
1919
- sigS: BytesLike;
1920
- sigV: BigNumberish;
1921
- },
1922
- overrides: Partial<{
1923
- userAddress: string;
1924
- contractAddress: string;
1925
- metaTxConfig: Partial<Omit<MetaTxConfig, "apiIds"> & { apiId: string }>;
1926
- metaTransactionMethod: string;
1927
- }> = {}
1928
- ): Promise<TransactionResponse> {
1929
- const { metaTxApiId, metaTxApiKey, metaTxRelayerUrl, contractAddress } =
1930
- this.assertAndGetMetaTxConfig(overrides);
1931
-
1932
- return metaTx.handler.relayMetaTransaction({
1933
- web3LibAdapter: this._web3Lib,
1934
- contractAddress,
1935
- chainId: this._chainId,
1936
- metaTx: {
1937
- config: {
1938
- relayerUrl: metaTxRelayerUrl,
1939
- apiId: metaTxApiId,
1940
- apiKey: metaTxApiKey
1941
- },
1942
- params: {
1943
- userAddress:
1944
- overrides.userAddress || (await this._web3Lib.getSignerAddress()),
1945
- functionName: metaTxParams.functionName,
1946
- functionSignature: metaTxParams.functionSignature,
1947
- nonce: metaTxParams.nonce,
1948
- sigR: metaTxParams.sigR,
1949
- sigS: metaTxParams.sigS,
1950
- sigV: metaTxParams.sigV
1951
- }
1952
- }
1953
- });
1954
- }
1955
-
1956
- /**
1957
- * Encodes and signs a native "token.approve()" meta transaction that can be relayed.
1958
- * @param exchangeToken - The address of the token contract.
1959
- * @param value - The value to be approved.
1960
- * @param overrides - Optionally specify a spender address (default is the protocol contract address).
1961
- * @returns Signature.
1962
- */
1963
- public async signNativeMetaTxApproveExchangeToken(
1964
- exchangeToken: string,
1965
- value: BigNumberish,
1966
- overrides: Partial<{
1967
- spender: string;
1968
- }> = {}
1969
- ) {
1970
- const user = await this._web3Lib.getSignerAddress();
1971
- return nativeMetaTx.handler.signNativeMetaTxApproveExchangeToken({
1972
- web3Lib: this._web3Lib,
1973
- chainId: this._chainId,
1974
- user,
1975
- exchangeToken,
1976
- spender: overrides.spender || this._protocolDiamond,
1977
- value
1978
- });
1979
- }
1980
-
1981
- /**
1982
- * Relay a native meta transaction,
1983
- * @param metaTxParams - Required params for meta transaction.
1984
- * @param overrides - Optional overrides.
1985
- * @returns Transaction response.
1986
- */
1987
- public async relayNativeMetaTransaction(
1988
- contractAddress: string,
1989
- metaTxParams: {
1990
- functionSignature: BytesLike;
1991
- sigR: BytesLike;
1992
- sigS: BytesLike;
1993
- sigV: BigNumberish;
1994
- },
1995
- overrides: Partial<{
1996
- userAddress: string;
1997
- metaTxConfig: Partial<Omit<MetaTxConfig, "apiIds"> & { apiId: string }>;
1998
- metaTransactionMethod: string;
1999
- }> = {}
2000
- ): Promise<TransactionResponse> {
2001
- const { metaTxApiId, metaTxApiKey, metaTxRelayerUrl } =
2002
- this.assertAndGetMetaTxConfig({ ...overrides, contractAddress });
2003
-
2004
- return nativeMetaTx.handler.relayNativeMetaTransaction({
2005
- web3LibAdapter: this._web3Lib,
2006
- contractAddress,
2007
- chainId: this._chainId,
2008
- metaTx: {
2009
- config: {
2010
- relayerUrl: metaTxRelayerUrl,
2011
- apiId: metaTxApiId,
2012
- apiKey: metaTxApiKey
2013
- },
2014
- params: {
2015
- userAddress:
2016
- overrides.userAddress || (await this._web3Lib.getSignerAddress()),
2017
- functionSignature: metaTxParams.functionSignature,
2018
- sigR: metaTxParams.sigR,
2019
- sigS: metaTxParams.sigS,
2020
- sigV: metaTxParams.sigV
2021
- }
2022
- }
2023
- });
2024
- }
2025
-
2026
- /**
2027
- * Returns information of submitted meta transaction.
2028
- * See https://docs.biconomy.io/api/native-meta-tx/get-retried-hashes.
2029
- * @param originalMetaTxHash - Original meta transaction as returned by `coreSDK.relayMetaTransaction`
2030
- * @param overrides - Optional overrides for meta transaction config.
2031
- * @returns - Additional meta transaction information.
2032
- */
2033
- public async getResubmittedMetaTx(
2034
- originalMetaTxHash: string,
2035
- overrides: Partial<{
2036
- contractAddress: string;
2037
- metaTxConfig: Partial<Omit<MetaTxConfig, "apiIds"> & { apiId: string }>;
2038
- metaTransactionMethod: string;
2039
- }> = {}
2040
- ): Promise<GetRetriedHashesData> {
2041
- const { metaTxApiId, metaTxApiKey, metaTxRelayerUrl } =
2042
- this.assertAndGetMetaTxConfig(overrides);
2043
-
2044
- return metaTx.handler.getResubmitted({
2045
- chainId: this._chainId,
2046
- metaTx: {
2047
- config: {
2048
- relayerUrl: metaTxRelayerUrl,
2049
- apiId: metaTxApiId,
2050
- apiKey: metaTxApiKey
2051
- },
2052
- originalHash: originalMetaTxHash
2053
- }
2054
- });
2055
- }
2056
-
2057
- private assertAndGetMetaTxConfig(
2058
- overrides: Partial<{
2059
- contractAddress: string;
2060
- metaTxConfig: Partial<Omit<MetaTxConfig, "apiIds"> & { apiId: string }>;
2061
- metaTransactionMethod: string;
2062
- }> = {}
2063
- ) {
2064
- const contractAddress = overrides.contractAddress || this._protocolDiamond;
2065
- const metaTransactionMethod =
2066
- overrides.metaTransactionMethod || "executeMetaTransaction";
2067
- const metaTxRelayerUrl =
2068
- overrides.metaTxConfig?.relayerUrl || this._metaTxConfig?.relayerUrl;
2069
- const metaTxApiKey =
2070
- overrides.metaTxConfig?.apiKey || this._metaTxConfig?.apiKey;
2071
- // metaTxApiId is depending on the contract/method(=executeMetaTransaction) to be called with Biconomy
2072
- const apiIds = this._metaTxConfig?.apiIds[contractAddress.toLowerCase()];
2073
- const metaTxApiId =
2074
- overrides.metaTxConfig?.apiId ||
2075
- (apiIds && apiIds[metaTransactionMethod]);
2076
-
2077
- if (!(metaTxRelayerUrl && metaTxApiKey && metaTxApiId)) {
2078
- throw new Error(
2079
- "CoreSDK not configured to relay meta transactions. Either pass in 'relayerUrl', 'apiKey' and 'apiId' during initialization OR as overrides arguments."
2080
- );
2081
- }
2082
-
2083
- return {
2084
- metaTxRelayerUrl,
2085
- metaTxApiId,
2086
- metaTxApiKey,
2087
- contractAddress
2088
- };
2089
- }
2090
-
2091
- /* -------------------------------------------------------------------------- */
2092
- /* Event logs */
2093
- /* -------------------------------------------------------------------------- */
2094
-
2095
- /**
2096
- * Returns event logs from subgraph.
2097
- * @param queryVars - Optional query variables to skip, order or filter.
2098
- * @returns Event log entities from subgraph.
2099
- */
2100
- public async getEventLogs(
2101
- queryVars?: subgraph.GetEventLogsQueryQueryVariables
2102
- ) {
2103
- return eventLogs.subgraph.getEventLogs(this._subgraphUrl, queryVars);
2104
- }
2105
-
2106
- /* -------------------------------------------------------------------------- */
2107
- /* Groups */
2108
- /* -------------------------------------------------------------------------- */
2109
-
2110
- /**
2111
- * Creates a group of contract addresses
2112
- * @param groupToCreate - group with the contract condition
2113
- * @param overrides - Optional overrides.
2114
- * @returns Transaction response.
2115
- */
2116
- public async createGroup(
2117
- groupToCreate: CreateGroupArgs,
2118
- overrides: Partial<{
2119
- contractAddress: string;
2120
- }> = {}
2121
- ): Promise<TransactionResponse> {
2122
- return groups.handler.createGroup({
2123
- groupToCreate,
2124
- contractAddress: overrides.contractAddress || this._protocolDiamond,
2125
- web3Lib: this._web3Lib
2126
- });
2127
- }
2128
-
2129
- /**
2130
- * Creates an offer with a specific conditions
2131
- * @param offerToCreate - Offer arguments.
2132
- * @param condition - contract condition applied to the offer
2133
- * @param overrides - Optional overrides.
2134
- * @returns Transaction response.
2135
- */
2136
- public async createOfferWithCondition(
2137
- offerToCreate: offers.CreateOfferArgs,
2138
- condition: ConditionStruct,
2139
- overrides: Partial<{
2140
- contractAddress: string;
2141
- }> = {}
2142
- ): Promise<TransactionResponse> {
2143
- return orchestration.handler.createOfferWithCondition({
2144
- offerToCreate,
2145
- contractAddress: overrides.contractAddress || this._protocolDiamond,
2146
- web3Lib: this._web3Lib,
2147
- metadataStorage: this._metadataStorage,
2148
- theGraphStorage: this._theGraphStorage,
2149
- condition
2150
- });
2151
- }
2152
- /**
2153
- * Creates a seller account and offer with a specific conditions
2154
- * This transaction only succeeds if there is no existing seller account for the connected signer.
2155
- * @param sellerToCreate - Addresses to set in the seller account.
2156
- * @param offerToCreate - Offer arguments.
2157
- * @param condition - contract condition applied to the offer
2158
- * @param overrides - Optional overrides.
2159
- * @returns Transaction response.
2160
- */
2161
- public async createSellerAndOfferWithCondition(
2162
- sellerToCreate: accounts.CreateSellerArgs,
2163
- offerToCreate: offers.CreateOfferArgs,
2164
- condition: ConditionStruct,
2165
- overrides: Partial<{
2166
- contractAddress: string;
2167
- }> = {}
2168
- ): Promise<TransactionResponse> {
2169
- return orchestration.handler.createSellerAndOfferWithCondition({
2170
- sellerToCreate,
2171
- offerToCreate,
2172
- contractAddress: overrides.contractAddress || this._protocolDiamond,
2173
- web3Lib: this._web3Lib,
2174
- metadataStorage: this._metadataStorage,
2175
- theGraphStorage: this._theGraphStorage,
2176
- condition
2177
- });
2178
- }
2179
- }
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
+ ]);