@bosonprotocol/core-sdk 1.39.1 → 1.40.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/dist/cjs/accounts/handler.d.ts +25 -1
  2. package/dist/cjs/accounts/handler.d.ts.map +1 -1
  3. package/dist/cjs/accounts/handler.js +38 -1
  4. package/dist/cjs/accounts/handler.js.map +1 -1
  5. package/dist/cjs/accounts/interface.d.ts +20 -3
  6. package/dist/cjs/accounts/interface.d.ts.map +1 -1
  7. package/dist/cjs/accounts/interface.js +29 -3
  8. package/dist/cjs/accounts/interface.js.map +1 -1
  9. package/dist/cjs/accounts/mixin.d.ts +12 -0
  10. package/dist/cjs/accounts/mixin.d.ts.map +1 -1
  11. package/dist/cjs/accounts/mixin.js +40 -0
  12. package/dist/cjs/accounts/mixin.js.map +1 -1
  13. package/dist/cjs/accounts/types.d.ts +4 -0
  14. package/dist/cjs/accounts/types.d.ts.map +1 -1
  15. package/dist/cjs/core-sdk.d.ts +2 -1
  16. package/dist/cjs/core-sdk.d.ts.map +1 -1
  17. package/dist/cjs/core-sdk.js +3 -1
  18. package/dist/cjs/core-sdk.js.map +1 -1
  19. package/dist/cjs/meta-tx/handler.js +3 -3
  20. package/dist/cjs/meta-tx/handler.js.map +1 -1
  21. package/dist/cjs/offers/handler.d.ts +13 -1
  22. package/dist/cjs/offers/handler.d.ts.map +1 -1
  23. package/dist/cjs/offers/handler.js +19 -1
  24. package/dist/cjs/offers/handler.js.map +1 -1
  25. package/dist/cjs/offers/interface.d.ts +10 -1
  26. package/dist/cjs/offers/interface.d.ts.map +1 -1
  27. package/dist/cjs/offers/interface.js +32 -15
  28. package/dist/cjs/offers/interface.js.map +1 -1
  29. package/dist/cjs/offers/mixin.d.ts +21 -1
  30. package/dist/cjs/offers/mixin.d.ts.map +1 -1
  31. package/dist/cjs/offers/mixin.js +42 -6
  32. package/dist/cjs/offers/mixin.js.map +1 -1
  33. package/dist/cjs/offers/renderContractualAgreement.d.ts.map +1 -1
  34. package/dist/cjs/offers/renderContractualAgreement.js +7 -1
  35. package/dist/cjs/offers/renderContractualAgreement.js.map +1 -1
  36. package/dist/cjs/offers/types.d.ts +1 -1
  37. package/dist/cjs/offers/types.d.ts.map +1 -1
  38. package/dist/cjs/offers/types.js +3 -0
  39. package/dist/cjs/offers/types.js.map +1 -1
  40. package/dist/cjs/orchestration/handler.d.ts +5 -4
  41. package/dist/cjs/orchestration/handler.d.ts.map +1 -1
  42. package/dist/cjs/orchestration/handler.js +4 -4
  43. package/dist/cjs/orchestration/handler.js.map +1 -1
  44. package/dist/cjs/orchestration/interface.d.ts +5 -4
  45. package/dist/cjs/orchestration/interface.d.ts.map +1 -1
  46. package/dist/cjs/orchestration/interface.js +22 -15
  47. package/dist/cjs/orchestration/interface.js.map +1 -1
  48. package/dist/cjs/orchestration/mixin.d.ts +5 -4
  49. package/dist/cjs/orchestration/mixin.d.ts.map +1 -1
  50. package/dist/cjs/orchestration/mixin.js +8 -8
  51. package/dist/cjs/orchestration/mixin.js.map +1 -1
  52. package/dist/cjs/protocol-config/handler.d.ts +6 -0
  53. package/dist/cjs/protocol-config/handler.d.ts.map +1 -0
  54. package/dist/cjs/protocol-config/handler.js +24 -0
  55. package/dist/cjs/protocol-config/handler.js.map +1 -0
  56. package/dist/cjs/protocol-config/index.d.ts +3 -0
  57. package/dist/cjs/protocol-config/index.d.ts.map +1 -0
  58. package/dist/cjs/protocol-config/index.js +29 -0
  59. package/dist/cjs/protocol-config/index.js.map +1 -0
  60. package/dist/cjs/protocol-config/interface.d.ts +5 -0
  61. package/dist/cjs/protocol-config/interface.d.ts.map +1 -0
  62. package/dist/cjs/protocol-config/interface.js +16 -0
  63. package/dist/cjs/protocol-config/interface.js.map +1 -0
  64. package/dist/cjs/protocol-config/mixin.d.ts +7 -0
  65. package/dist/cjs/protocol-config/mixin.d.ts.map +1 -0
  66. package/dist/cjs/protocol-config/mixin.js +26 -0
  67. package/dist/cjs/protocol-config/mixin.js.map +1 -0
  68. package/dist/cjs/subgraph.d.ts +6057 -298
  69. package/dist/cjs/subgraph.d.ts.map +1 -1
  70. package/dist/cjs/subgraph.js +143 -16
  71. package/dist/cjs/subgraph.js.map +1 -1
  72. package/dist/esm/accounts/handler.d.ts +25 -1
  73. package/dist/esm/accounts/handler.d.ts.map +1 -1
  74. package/dist/esm/accounts/handler.js +26 -1
  75. package/dist/esm/accounts/handler.js.map +1 -1
  76. package/dist/esm/accounts/interface.d.ts +20 -3
  77. package/dist/esm/accounts/interface.d.ts.map +1 -1
  78. package/dist/esm/accounts/interface.js +23 -2
  79. package/dist/esm/accounts/interface.js.map +1 -1
  80. package/dist/esm/accounts/mixin.d.ts +12 -0
  81. package/dist/esm/accounts/mixin.d.ts.map +1 -1
  82. package/dist/esm/accounts/mixin.js +32 -0
  83. package/dist/esm/accounts/mixin.js.map +1 -1
  84. package/dist/esm/accounts/types.d.ts +4 -0
  85. package/dist/esm/accounts/types.d.ts.map +1 -1
  86. package/dist/esm/core-sdk.d.ts +2 -1
  87. package/dist/esm/core-sdk.d.ts.map +1 -1
  88. package/dist/esm/core-sdk.js +3 -1
  89. package/dist/esm/core-sdk.js.map +1 -1
  90. package/dist/esm/meta-tx/handler.js +3 -3
  91. package/dist/esm/meta-tx/handler.js.map +1 -1
  92. package/dist/esm/offers/handler.d.ts +13 -1
  93. package/dist/esm/offers/handler.d.ts.map +1 -1
  94. package/dist/esm/offers/handler.js +13 -1
  95. package/dist/esm/offers/handler.js.map +1 -1
  96. package/dist/esm/offers/interface.d.ts +10 -1
  97. package/dist/esm/offers/interface.d.ts.map +1 -1
  98. package/dist/esm/offers/interface.js +35 -15
  99. package/dist/esm/offers/interface.js.map +1 -1
  100. package/dist/esm/offers/mixin.d.ts +21 -1
  101. package/dist/esm/offers/mixin.d.ts.map +1 -1
  102. package/dist/esm/offers/mixin.js +34 -4
  103. package/dist/esm/offers/mixin.js.map +1 -1
  104. package/dist/esm/offers/renderContractualAgreement.d.ts.map +1 -1
  105. package/dist/esm/offers/renderContractualAgreement.js +11 -2
  106. package/dist/esm/offers/renderContractualAgreement.js.map +1 -1
  107. package/dist/esm/offers/types.d.ts +1 -1
  108. package/dist/esm/offers/types.d.ts.map +1 -1
  109. package/dist/esm/offers/types.js +1 -1
  110. package/dist/esm/offers/types.js.map +1 -1
  111. package/dist/esm/orchestration/handler.d.ts +5 -4
  112. package/dist/esm/orchestration/handler.d.ts.map +1 -1
  113. package/dist/esm/orchestration/handler.js +4 -4
  114. package/dist/esm/orchestration/handler.js.map +1 -1
  115. package/dist/esm/orchestration/interface.d.ts +5 -4
  116. package/dist/esm/orchestration/interface.d.ts.map +1 -1
  117. package/dist/esm/orchestration/interface.js +22 -15
  118. package/dist/esm/orchestration/interface.js.map +1 -1
  119. package/dist/esm/orchestration/mixin.d.ts +5 -4
  120. package/dist/esm/orchestration/mixin.d.ts.map +1 -1
  121. package/dist/esm/orchestration/mixin.js +8 -8
  122. package/dist/esm/orchestration/mixin.js.map +1 -1
  123. package/dist/esm/protocol-config/handler.d.ts +6 -0
  124. package/dist/esm/protocol-config/handler.d.ts.map +1 -0
  125. package/dist/esm/protocol-config/handler.js +9 -0
  126. package/dist/esm/protocol-config/handler.js.map +1 -0
  127. package/dist/esm/protocol-config/index.d.ts +3 -0
  128. package/dist/esm/protocol-config/index.d.ts.map +1 -0
  129. package/dist/esm/protocol-config/index.js +3 -0
  130. package/dist/esm/protocol-config/index.js.map +1 -0
  131. package/dist/esm/protocol-config/interface.d.ts +5 -0
  132. package/dist/esm/protocol-config/interface.d.ts.map +1 -0
  133. package/dist/esm/protocol-config/interface.js +11 -0
  134. package/dist/esm/protocol-config/interface.js.map +1 -0
  135. package/dist/esm/protocol-config/mixin.d.ts +7 -0
  136. package/dist/esm/protocol-config/mixin.d.ts.map +1 -0
  137. package/dist/esm/protocol-config/mixin.js +11 -0
  138. package/dist/esm/protocol-config/mixin.js.map +1 -0
  139. package/dist/esm/subgraph.d.ts +6057 -298
  140. package/dist/esm/subgraph.d.ts.map +1 -1
  141. package/dist/esm/subgraph.js +139 -12
  142. package/dist/esm/subgraph.js.map +1 -1
  143. package/package.json +3 -3
  144. package/src/accounts/handler.ts +57 -2
  145. package/src/accounts/interface.ts +66 -6
  146. package/src/accounts/mixin.ts +60 -0
  147. package/src/accounts/queries.graphql +14 -1
  148. package/src/accounts/types.ts +5 -0
  149. package/src/core-sdk.ts +5 -2
  150. package/src/meta-tx/handler.ts +3 -3
  151. package/src/offers/handler.ts +29 -2
  152. package/src/offers/interface.ts +74 -16
  153. package/src/offers/mixin.ts +56 -11
  154. package/src/offers/queries.graphql +11 -0
  155. package/src/offers/renderContractualAgreement.ts +11 -2
  156. package/src/offers/types.ts +1 -1
  157. package/src/orchestration/handler.ts +9 -8
  158. package/src/orchestration/interface.ts +23 -15
  159. package/src/orchestration/mixin.ts +9 -8
  160. package/src/protocol-config/handler.ts +16 -0
  161. package/src/protocol-config/index.ts +2 -0
  162. package/src/protocol-config/interface.ts +18 -0
  163. package/src/protocol-config/mixin.ts +15 -0
  164. package/src/subgraph.ts +5284 -299
@@ -22,7 +22,12 @@ import {
22
22
  encodeIsSellerSaltAvailable,
23
23
  decodeIsSellerSaltAvailable,
24
24
  encodeCalculateCollectionAddress,
25
- decodeCalculateCollectionAddress
25
+ decodeCalculateCollectionAddress,
26
+ encodeAddRoyaltyRecipients,
27
+ encodeUpdateRoyaltyRecipients,
28
+ encodeGetRoyaltyRecipients,
29
+ decodeGetRoyaltyRecipients,
30
+ encodeRemoveRoyaltyRecipients
26
31
  } from "./interface";
27
32
  import { getDisputeResolverById } from "./subgraph";
28
33
  import {
@@ -33,7 +38,8 @@ import {
33
38
  DisputeResolverUpdates,
34
39
  OptInToSellerUpdateArgs,
35
40
  OptInToDisputeResolverUpdateArgs,
36
- CreateCollectionArgs
41
+ CreateCollectionArgs,
42
+ RoyaltyRecipientInfo
37
43
  } from "./types";
38
44
  import { storeMetadataOnTheGraph } from "../offers/storage";
39
45
 
@@ -291,3 +297,52 @@ export async function calculateCollectionAddress(args: {
291
297
  });
292
298
  return decodeCalculateCollectionAddress(result);
293
299
  }
300
+
301
+ export async function addRoyaltyRecipients(args: {
302
+ sellerId: BigNumberish;
303
+ royaltyRecipients: RoyaltyRecipientInfo[];
304
+ contractAddress: string;
305
+ web3Lib: Web3LibAdapter;
306
+ }): Promise<TransactionResponse> {
307
+ return args.web3Lib.sendTransaction({
308
+ to: args.contractAddress,
309
+ data: encodeAddRoyaltyRecipients(args)
310
+ });
311
+ }
312
+
313
+ export async function updateRoyaltyRecipients(args: {
314
+ sellerId: BigNumberish;
315
+ royaltyRecipientIds: BigNumberish[];
316
+ royaltyRecipients: RoyaltyRecipientInfo[];
317
+ contractAddress: string;
318
+ web3Lib: Web3LibAdapter;
319
+ }): Promise<TransactionResponse> {
320
+ return args.web3Lib.sendTransaction({
321
+ to: args.contractAddress,
322
+ data: encodeUpdateRoyaltyRecipients(args)
323
+ });
324
+ }
325
+
326
+ export async function removeRoyaltyRecipients(args: {
327
+ sellerId: BigNumberish;
328
+ royaltyRecipientIds: BigNumberish[];
329
+ contractAddress: string;
330
+ web3Lib: Web3LibAdapter;
331
+ }): Promise<TransactionResponse> {
332
+ return args.web3Lib.sendTransaction({
333
+ to: args.contractAddress,
334
+ data: encodeRemoveRoyaltyRecipients(args)
335
+ });
336
+ }
337
+
338
+ export async function getRoyaltyRecipients(args: {
339
+ sellerId: BigNumberish;
340
+ contractAddress: string;
341
+ web3Lib: Web3LibAdapter;
342
+ }): Promise<RoyaltyRecipientInfo[]> {
343
+ const result = await args.web3Lib.call({
344
+ to: args.contractAddress,
345
+ data: encodeGetRoyaltyRecipients(args)
346
+ });
347
+ return decodeGetRoyaltyRecipients(result);
348
+ }
@@ -1,6 +1,6 @@
1
1
  import { Interface } from "@ethersproject/abi";
2
2
  import { formatBytes32String } from "@ethersproject/strings";
3
- import { BigNumberish } from "@ethersproject/bignumber";
3
+ import { BigNumberish, BigNumber } from "@ethersproject/bignumber";
4
4
  import {
5
5
  CreateSellerArgs,
6
6
  CreateDisputeResolverArgs,
@@ -16,7 +16,8 @@ import {
16
16
  SellerUpdateFields,
17
17
  OptInToDisputeResolverUpdateArgs,
18
18
  DisputeResolverUpdateFields,
19
- CreateCollectionArgs
19
+ CreateCollectionArgs,
20
+ RoyaltyRecipientInfo
20
21
  } from "./types";
21
22
  import { AddressZero } from "@ethersproject/constants";
22
23
  import { INITIAL_COLLECTION_ID } from "./handler";
@@ -146,7 +147,16 @@ export function createSellerArgsToStruct(
146
147
  args: CreateSellerArgs,
147
148
  collectionSalt: string
148
149
  ): {
149
- sellerStruct: Partial<SellerStruct>;
150
+ sellerStruct: Pick<
151
+ SellerStruct,
152
+ | "id"
153
+ | "assistant"
154
+ | "admin"
155
+ | "clerk"
156
+ | "treasury"
157
+ | "active"
158
+ | "metadataUri"
159
+ >;
150
160
  authTokenStruct: AuthTokenStruct;
151
161
  voucherInitValues: VoucherInitValuesStruct;
152
162
  } {
@@ -175,7 +185,7 @@ export function createCollectionArgsToStruct(args: CreateCollectionArgs): {
175
185
  externalId: string;
176
186
  voucherInitValues: VoucherInitValuesStruct;
177
187
  } {
178
- const { collectionId, contractUri, royaltyPercentage } = args;
188
+ const { collectionId, contractUri } = args;
179
189
  const collectionSalt =
180
190
  args.collectionSalt ||
181
191
  formatBytes32String(collectionId || INITIAL_COLLECTION_ID);
@@ -183,7 +193,7 @@ export function createCollectionArgsToStruct(args: CreateCollectionArgs): {
183
193
  externalId: collectionId,
184
194
  voucherInitValues: {
185
195
  contractURI: contractUri,
186
- royaltyPercentage,
196
+ royaltyPercentage: "0", // useless after protocol v2.4.0
187
197
  collectionSalt
188
198
  }
189
199
  };
@@ -205,7 +215,10 @@ function argsToSellerStruct(args: {
205
215
  admin: string;
206
216
  treasury: string;
207
217
  metadataUri: string;
208
- }): Partial<SellerStruct> {
218
+ }): Pick<
219
+ SellerStruct,
220
+ "id" | "assistant" | "admin" | "clerk" | "treasury" | "active" | "metadataUri"
221
+ > {
209
222
  return {
210
223
  // NOTE: It doesn't matter which values we set for `id` and `active` here
211
224
  // as they will be overridden by the contract. But to conform to the struct
@@ -273,3 +286,50 @@ export function decodeCalculateCollectionAddress(result: string): {
273
286
  );
274
287
  return { collectionAddress, isAvailable };
275
288
  }
289
+
290
+ export function encodeAddRoyaltyRecipients(args: {
291
+ sellerId: BigNumberish;
292
+ royaltyRecipients: RoyaltyRecipientInfo[];
293
+ }) {
294
+ return bosonAccountHandlerIface.encodeFunctionData("addRoyaltyRecipients", [
295
+ args.sellerId,
296
+ args.royaltyRecipients
297
+ ]);
298
+ }
299
+
300
+ export function encodeUpdateRoyaltyRecipients(args: {
301
+ sellerId: BigNumberish;
302
+ royaltyRecipientIds: BigNumberish[];
303
+ royaltyRecipients: RoyaltyRecipientInfo[];
304
+ }) {
305
+ return bosonAccountHandlerIface.encodeFunctionData(
306
+ "updateRoyaltyRecipients",
307
+ [args.sellerId, args.royaltyRecipientIds, args.royaltyRecipients]
308
+ );
309
+ }
310
+
311
+ export function encodeRemoveRoyaltyRecipients(args: {
312
+ sellerId: BigNumberish;
313
+ royaltyRecipientIds: BigNumberish[];
314
+ }) {
315
+ return bosonAccountHandlerIface.encodeFunctionData(
316
+ "removeRoyaltyRecipients",
317
+ [args.sellerId, args.royaltyRecipientIds]
318
+ );
319
+ }
320
+
321
+ export function encodeGetRoyaltyRecipients(args: { sellerId: BigNumberish }) {
322
+ return bosonAccountHandlerIface.encodeFunctionData("getRoyaltyRecipients", [
323
+ args.sellerId
324
+ ]);
325
+ }
326
+
327
+ export function decodeGetRoyaltyRecipients(
328
+ result: string
329
+ ): RoyaltyRecipientInfo[] {
330
+ const [royaltyRecipients] = bosonAccountHandlerIface.decodeFunctionResult(
331
+ "getRoyaltyRecipients",
332
+ result
333
+ );
334
+ return royaltyRecipients;
335
+ }
@@ -620,4 +620,64 @@ export class AccountsMixin extends BaseCoreSDK {
620
620
  ): Promise<subgraph.OfferCollectionFieldsFragment[]> {
621
621
  return accounts.subgraph.getOfferCollections(this._subgraphUrl, queryVars);
622
622
  }
623
+
624
+ public async addRoyaltyRecipients(
625
+ sellerId: BigNumberish,
626
+ royaltyRecipients: accounts.RoyaltyRecipientInfo[],
627
+ overrides: Partial<{
628
+ contractAddress: string;
629
+ }> = {}
630
+ ) {
631
+ return accounts.handler.addRoyaltyRecipients({
632
+ sellerId,
633
+ royaltyRecipients,
634
+ web3Lib: this._web3Lib,
635
+ contractAddress: overrides.contractAddress || this._protocolDiamond
636
+ });
637
+ }
638
+
639
+ public async updateRoyaltyRecipients(
640
+ sellerId: BigNumberish,
641
+ royaltyRecipientIds: BigNumberish[],
642
+ royaltyRecipients: accounts.RoyaltyRecipientInfo[],
643
+ overrides: Partial<{
644
+ contractAddress: string;
645
+ }> = {}
646
+ ) {
647
+ return accounts.handler.updateRoyaltyRecipients({
648
+ sellerId,
649
+ royaltyRecipientIds,
650
+ royaltyRecipients,
651
+ web3Lib: this._web3Lib,
652
+ contractAddress: overrides.contractAddress || this._protocolDiamond
653
+ });
654
+ }
655
+
656
+ public async removeRoyaltyRecipients(
657
+ sellerId: BigNumberish,
658
+ royaltyRecipientIds: BigNumberish[],
659
+ overrides: Partial<{
660
+ contractAddress: string;
661
+ }> = {}
662
+ ) {
663
+ return accounts.handler.removeRoyaltyRecipients({
664
+ sellerId,
665
+ royaltyRecipientIds,
666
+ web3Lib: this._web3Lib,
667
+ contractAddress: overrides.contractAddress || this._protocolDiamond
668
+ });
669
+ }
670
+
671
+ public async getRoyaltyRecipients(
672
+ sellerId: BigNumberish,
673
+ overrides: Partial<{
674
+ contractAddress: string;
675
+ }> = {}
676
+ ) {
677
+ return accounts.handler.getRoyaltyRecipients({
678
+ sellerId,
679
+ web3Lib: this._web3Lib,
680
+ contractAddress: overrides.contractAddress || this._protocolDiamond
681
+ });
682
+ }
623
683
  }
@@ -380,7 +380,20 @@ fragment BaseSellerFields on Seller {
380
380
  voucherCloneAddress
381
381
  active
382
382
  contractURI
383
- royaltyPercentage
383
+ royaltyRecipients {
384
+ id
385
+ recipient {
386
+ id
387
+ wallet
388
+ royalties {
389
+ bps
390
+ offer {
391
+ id
392
+ }
393
+ }
394
+ }
395
+ minRoyaltyPercentage
396
+ }
384
397
  metadataUri
385
398
  metadata {
386
399
  id
@@ -45,3 +45,8 @@ export type DisputeResolverUpdates = Partial<
45
45
  escalationResponsePeriodInMS: BigNumberish;
46
46
  }
47
47
  >;
48
+
49
+ export type RoyaltyRecipientInfo = {
50
+ wallet: string;
51
+ minRoyaltyPercentage: BigNumberish;
52
+ };
package/src/core-sdk.ts CHANGED
@@ -24,6 +24,7 @@ import { ERC20Mixin } from "./erc20/mixin";
24
24
  import { ERC721Mixin } from "./erc721/mixin";
25
25
  import { ERC1155Mixin } from "./erc1155/mixin";
26
26
  import { ERC165Mixin } from "./erc165/mixin";
27
+ import { ProtocolConfigMixin } from "./protocol-config/mixin";
27
28
 
28
29
  export class CoreSDK extends BaseCoreSDK {
29
30
  /**
@@ -143,7 +144,8 @@ export interface CoreSDK
143
144
  ERC20Mixin,
144
145
  ERC721Mixin,
145
146
  ERC1155Mixin,
146
- ERC165Mixin {}
147
+ ERC165Mixin,
148
+ ProtocolConfigMixin {}
147
149
  applyMixins(CoreSDK, [
148
150
  MetadataMixin,
149
151
  AccountsMixin,
@@ -160,5 +162,6 @@ applyMixins(CoreSDK, [
160
162
  ERC20Mixin,
161
163
  ERC721Mixin,
162
164
  ERC1155Mixin,
163
- ERC165Mixin
165
+ ERC165Mixin,
166
+ ProtocolConfigMixin
164
167
  ]);
@@ -472,7 +472,7 @@ export async function signMetaTxCreateOffer(
472
472
  return signMetaTx({
473
473
  ...args,
474
474
  functionName:
475
- "createOffer((uint256,uint256,uint256,uint256,uint256,uint256,address,string,string,bool,uint256),(uint256,uint256,uint256,uint256),(uint256,uint256,uint256),uint256,uint256)",
475
+ "createOffer((uint256,uint256,uint256,uint256,uint256,uint256,address,uint8,string,string,bool,uint256,(address[],uint256[])[]),(uint256,uint256,uint256,uint256),(uint256,uint256,uint256),uint256,uint256,uint256)",
476
476
  functionSignature: encodeCreateOffer(args.createOfferArgs)
477
477
  });
478
478
  }
@@ -504,7 +504,7 @@ export async function signMetaTxCreateOfferBatch(
504
504
  return signMetaTx({
505
505
  ...args,
506
506
  functionName:
507
- "createOfferBatch((uint256,uint256,uint256,uint256,uint256,uint256,address,string,string,bool,uint256)[],(uint256,uint256,uint256,uint256)[],(uint256,uint256,uint256)[],uint256[],uint256[])",
507
+ "createOfferBatch((uint256,uint256,uint256,uint256,uint256,uint256,address,uint8,string,string,bool,uint256,(address[],uint256[])[])[],(uint256,uint256,uint256,uint256)[],(uint256,uint256,uint256)[],uint256[],uint256[],uint256[])",
508
508
  functionSignature: encodeCreateOfferBatch(args.createOffersArgs)
509
509
  });
510
510
  }
@@ -809,7 +809,7 @@ export async function signMetaTxCreateOfferWithCondition(
809
809
  return signMetaTx({
810
810
  ...args,
811
811
  functionName:
812
- "createOfferWithCondition((uint256,uint256,uint256,uint256,uint256,uint256,address,string,string,bool,uint256),(uint256,uint256,uint256,uint256),(uint256,uint256,uint256),uint256,(uint8,uint8,address,uint8,uint256,uint256,uint256,uint256),uint256)",
812
+ "createOfferWithCondition((uint256,uint256,uint256,uint256,uint256,uint256,address,uint8,string,string,bool,uint256,(address[],uint256[])[]),(uint256,uint256,uint256,uint256),(uint256,uint256,uint256),uint256,(uint8,uint8,address,uint8,uint256,uint256,uint256,uint256),uint256,uint256)",
813
813
  functionSignature: encodeCreateOfferWithCondition(
814
814
  args.offerToCreate,
815
815
  args.condition
@@ -3,13 +3,16 @@ import {
3
3
  Web3LibAdapter,
4
4
  TransactionResponse,
5
5
  MetadataStorage,
6
- utils
6
+ utils,
7
+ RoyaltyInfo
7
8
  } from "@bosonprotocol/common";
8
9
  import {
9
10
  bosonOfferHandlerIface,
10
11
  encodeCreateOffer,
11
12
  encodeCreateOfferBatch,
12
- encodeReserveRange
13
+ encodeReserveRange,
14
+ encodeUpdateOfferRoyaltyRecipients,
15
+ encodeUpdateOfferRoyaltyRecipientsBatch
13
16
  } from "./interface";
14
17
  import { getOfferById, getOffers } from "./subgraph";
15
18
  import { storeMetadataOnTheGraph } from "./storage";
@@ -189,6 +192,30 @@ export async function extendOfferBatch(args: {
189
192
  });
190
193
  }
191
194
 
195
+ export async function updateOfferRoyaltyRecipients(args: {
196
+ contractAddress: string;
197
+ web3Lib: Web3LibAdapter;
198
+ offerId: BigNumberish;
199
+ royaltyInfo: RoyaltyInfo;
200
+ }) {
201
+ return args.web3Lib.sendTransaction({
202
+ to: args.contractAddress,
203
+ data: encodeUpdateOfferRoyaltyRecipients(args)
204
+ });
205
+ }
206
+
207
+ export async function updateOfferRoyaltyRecipientsBatch(args: {
208
+ contractAddress: string;
209
+ web3Lib: Web3LibAdapter;
210
+ offerIds: BigNumberish[];
211
+ royaltyInfo: RoyaltyInfo;
212
+ }) {
213
+ return args.web3Lib.sendTransaction({
214
+ to: args.contractAddress,
215
+ data: encodeUpdateOfferRoyaltyRecipientsBatch(args)
216
+ });
217
+ }
218
+
192
219
  function checkIfOfferVoidable(
193
220
  offerId: BigNumberish,
194
221
  signerAddress: string,
@@ -3,12 +3,15 @@ import {
3
3
  utils,
4
4
  abis,
5
5
  OfferDatesStruct,
6
- OfferDurationsStruct
6
+ OfferDurationsStruct,
7
+ PriceType,
8
+ RoyaltyInfo
7
9
  } from "@bosonprotocol/common";
8
10
  import { Interface } from "@ethersproject/abi";
9
11
  import { getAddress } from "@ethersproject/address";
10
12
  import { BigNumberish } from "@ethersproject/bignumber";
11
13
  import { CreateOfferArgs } from "./types";
14
+ import { AddressZero } from "@ethersproject/constants";
12
15
 
13
16
  export const bosonOfferHandlerIface = new Interface(abis.IBosonOfferHandlerABI);
14
17
 
@@ -19,39 +22,69 @@ export function encodeCreateOffer(args: CreateOfferArgs) {
19
22
  );
20
23
  }
21
24
 
25
+ export function encodeUpdateOfferRoyaltyRecipients(args: {
26
+ offerId: BigNumberish;
27
+ royaltyInfo: RoyaltyInfo;
28
+ }) {
29
+ return bosonOfferHandlerIface.encodeFunctionData(
30
+ "updateOfferRoyaltyRecipients",
31
+ [args.offerId, args.royaltyInfo]
32
+ );
33
+ }
34
+
35
+ export function encodeUpdateOfferRoyaltyRecipientsBatch(args: {
36
+ offerIds: BigNumberish[];
37
+ royaltyInfo: RoyaltyInfo;
38
+ }) {
39
+ return bosonOfferHandlerIface.encodeFunctionData(
40
+ "updateOfferRoyaltyRecipientsBatch",
41
+ [args.offerIds, args.royaltyInfo]
42
+ );
43
+ }
44
+
22
45
  export function encodeCreateOfferBatch(argsBatch: CreateOfferArgs[]) {
23
46
  const argsTuples: [
24
47
  Partial<OfferStruct>,
25
48
  Partial<OfferDatesStruct>,
26
49
  Partial<OfferDurationsStruct>,
27
50
  BigNumberish,
51
+ BigNumberish,
28
52
  BigNumberish
29
- ][] = argsBatch.map((args) => [
30
- argsToOfferStruct(args),
31
- argsToOfferDatesStruct(args),
32
- argsToOfferDurationsStruct(args),
33
- args.disputeResolverId,
34
- args.agentId
35
- ]);
36
- const [offers, offerDates, offerDurations, disputeResolverIds, agentIds]: [
53
+ ][] = argsBatch.map((args) => createOfferArgsToStructs(args));
54
+ const [
55
+ offers,
56
+ offerDates,
57
+ offerDurations,
58
+ disputeResolverIds,
59
+ agentIds,
60
+ feeLimits
61
+ ]: [
37
62
  Partial<OfferStruct>[],
38
63
  Partial<OfferDatesStruct>[],
39
64
  Partial<OfferDurationsStruct>[],
40
65
  BigNumberish[],
66
+ BigNumberish[],
41
67
  BigNumberish[]
42
68
  ] = argsTuples.reduce(
43
69
  (acc, tuple) => {
44
- const [offer, offerDates, offerDurations, disputeResolverId, agentId] =
45
- tuple;
70
+ const [
71
+ offer,
72
+ offerDates,
73
+ offerDurations,
74
+ disputeResolverId,
75
+ agentId,
76
+ feeLimit
77
+ ] = tuple;
46
78
  return [
47
79
  [...acc[0], offer],
48
80
  [...acc[1], offerDates],
49
81
  [...acc[2], offerDurations],
50
82
  [...acc[3], disputeResolverId],
51
- [...acc[4], agentId]
83
+ [...acc[4], agentId],
84
+ [...acc[5], feeLimit]
52
85
  ];
53
86
  },
54
- [[], [], [], [], []]
87
+ [[], [], [], [], [], []]
55
88
  );
56
89
 
57
90
  return bosonOfferHandlerIface.encodeFunctionData("createOfferBatch", [
@@ -59,7 +92,8 @@ export function encodeCreateOfferBatch(argsBatch: CreateOfferArgs[]) {
59
92
  offerDates,
60
93
  offerDurations,
61
94
  disputeResolverIds,
62
- agentIds
95
+ agentIds,
96
+ feeLimits
63
97
  ]);
64
98
  }
65
99
 
@@ -70,25 +104,49 @@ export function createOfferArgsToStructs(
70
104
  Partial<OfferDatesStruct>,
71
105
  Partial<OfferDurationsStruct>,
72
106
  BigNumberish,
107
+ BigNumberish,
73
108
  BigNumberish
74
109
  ] {
110
+ const feeLimit = args.feeLimit !== undefined ? args.feeLimit : args.price;
75
111
  return [
76
112
  argsToOfferStruct(args),
77
113
  argsToOfferDatesStruct(args),
78
114
  argsToOfferDurationsStruct(args),
79
115
  args.disputeResolverId,
80
- args.agentId
116
+ args.agentId,
117
+ feeLimit
81
118
  ];
82
119
  }
83
120
 
84
121
  export function argsToOfferStruct(args: CreateOfferArgs): Partial<OfferStruct> {
85
122
  const { exchangeToken, ...restArgs } = args;
86
123
 
124
+ const priceType =
125
+ args.priceType !== undefined ? args.priceType : PriceType.Static;
126
+ const royaltyInfo =
127
+ args.royaltyInfo !== undefined
128
+ ? args.royaltyInfo
129
+ : [
130
+ {
131
+ recipients: [],
132
+ bps: []
133
+ }
134
+ ];
135
+
87
136
  return {
88
137
  id: "0",
89
138
  sellerId: "0",
90
139
  ...restArgs,
91
- exchangeToken: getAddress(exchangeToken)
140
+ exchangeToken: getAddress(exchangeToken),
141
+ priceType,
142
+ royaltyInfo: royaltyInfo.map((royaltyInfoItem) => {
143
+ return {
144
+ ...royaltyInfoItem,
145
+ recipients: royaltyInfoItem.recipients.map((recipient) =>
146
+ getAddress(recipient)
147
+ )
148
+ };
149
+ })
92
150
  };
93
151
  }
94
152
 
@@ -12,7 +12,8 @@ import {
12
12
  Log,
13
13
  TokenType,
14
14
  EvaluationMethod,
15
- GatingType
15
+ GatingType,
16
+ RoyaltyInfo
16
17
  } from "@bosonprotocol/common";
17
18
  import groupBy from "lodash/groupBy";
18
19
  import { BigNumber, BigNumberish } from "@ethersproject/bignumber";
@@ -78,7 +79,7 @@ export class OfferMixin extends BaseCoreSDK {
78
79
  * @returns Created offer id.
79
80
  */
80
81
  public getCreatedOfferIdFromLogs(logs: Log[]): string | null {
81
- const offerId = getValueFromLogs<string>({
82
+ const offerId = getValueFromLogs<BigNumber>({
82
83
  iface: offers.iface.bosonOfferHandlerIface,
83
84
  logs,
84
85
  eventArgsKey: "offerId",
@@ -87,13 +88,13 @@ export class OfferMixin extends BaseCoreSDK {
87
88
 
88
89
  return (
89
90
  offerId ||
90
- getValueFromLogs({
91
+ getValueFromLogs<BigNumber>({
91
92
  iface: orchestration.iface.bosonOrchestrationHandlerIface,
92
93
  logs,
93
94
  eventArgsKey: "offerId",
94
95
  eventName: "OfferCreated"
95
96
  })
96
- );
97
+ )?.toString();
97
98
  }
98
99
 
99
100
  /**
@@ -102,12 +103,12 @@ export class OfferMixin extends BaseCoreSDK {
102
103
  * @returns Array of created offerIds.
103
104
  */
104
105
  public getCreatedOfferIdsFromLogs(logs: Log[]): string[] {
105
- return getValuesFromLogs({
106
+ return getValuesFromLogs<BigNumber>({
106
107
  iface: offers.iface.bosonOfferHandlerIface,
107
108
  logs,
108
109
  eventArgsKey: "offerId",
109
110
  eventName: "OfferCreated"
110
- });
111
+ }).map((o) => o.toString());
111
112
  }
112
113
 
113
114
  /**
@@ -116,12 +117,12 @@ export class OfferMixin extends BaseCoreSDK {
116
117
  * @returns Array of group Ids.
117
118
  */
118
119
  public getCreatedGroupIdsFromLogs(logs: Log[]): string[] {
119
- return getValuesFromLogs({
120
+ return getValuesFromLogs<BigNumber>({
120
121
  iface: groups.iface.bosonGroupHandlerIface,
121
122
  logs,
122
123
  eventArgsKey: "groupId",
123
124
  eventName: "GroupCreated"
124
- });
125
+ }).map((g) => g.toString());
125
126
  }
126
127
 
127
128
  /**
@@ -131,7 +132,7 @@ export class OfferMixin extends BaseCoreSDK {
131
132
  * @returns Created offer id.
132
133
  */
133
134
  public getCreatedSellerIdFromLogs(logs: Log[]): string | null {
134
- const sellerId = getValueFromLogs<string>({
135
+ const sellerId = getValueFromLogs<BigNumber>({
135
136
  iface: accounts.iface.bosonAccountHandlerIface,
136
137
  logs,
137
138
  eventArgsKey: "sellerId",
@@ -140,13 +141,13 @@ export class OfferMixin extends BaseCoreSDK {
140
141
 
141
142
  return (
142
143
  sellerId ||
143
- getValueFromLogs({
144
+ getValueFromLogs<BigNumber>({
144
145
  iface: orchestration.iface.bosonOrchestrationHandlerIface,
145
146
  logs,
146
147
  eventArgsKey: "sellerId",
147
148
  eventName: "SellerCreated"
148
149
  })
149
- );
150
+ )?.toString();
150
151
  }
151
152
 
152
153
  /**
@@ -681,4 +682,48 @@ export class OfferMixin extends BaseCoreSDK {
681
682
  );
682
683
  return offers.checkExchangePolicy(offerData, rules);
683
684
  }
685
+
686
+ /**
687
+ * Sets new valid royalty info to a given offer.
688
+ * @param offerId - Id of the offer
689
+ * @param royaltyInfo - new royaltyInfo to be applied
690
+ * @param overrides - Optional overrides.
691
+ * @returns Transaction response.
692
+ */
693
+ public async updateOfferRoyaltyRecipients(
694
+ offerId: BigNumberish,
695
+ royaltyInfo: RoyaltyInfo,
696
+ overrides: Partial<{
697
+ contractAddress: string;
698
+ }> = {}
699
+ ): Promise<TransactionResponse> {
700
+ return offers.handler.updateOfferRoyaltyRecipients({
701
+ offerId,
702
+ royaltyInfo,
703
+ web3Lib: this._web3Lib,
704
+ contractAddress: overrides.contractAddress || this._protocolDiamond
705
+ });
706
+ }
707
+
708
+ /**
709
+ * Sets new valid until date for a batch of offers.
710
+ * @param offerIds - list of ids of the offers to extend
711
+ * @param royaltyInfo - new royaltyInfo to be applied
712
+ * @param overrides - Optional overrides.
713
+ * @returns Transaction response.
714
+ */
715
+ public async updateOfferRoyaltyRecipientsBatch(
716
+ offerIds: BigNumberish[],
717
+ royaltyInfo: RoyaltyInfo,
718
+ overrides: Partial<{
719
+ contractAddress: string;
720
+ }> = {}
721
+ ): Promise<TransactionResponse> {
722
+ return offers.handler.updateOfferRoyaltyRecipientsBatch({
723
+ offerIds,
724
+ royaltyInfo,
725
+ web3Lib: this._web3Lib,
726
+ contractAddress: overrides.contractAddress || this._protocolDiamond
727
+ });
728
+ }
684
729
  }