@bosonprotocol/core-sdk 1.1.0 → 1.1.1-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 (109) hide show
  1. package/dist/cjs/core-sdk.d.ts +1 -0
  2. package/dist/cjs/core-sdk.d.ts.map +1 -0
  3. package/dist/cjs/core-sdk.js +1 -0
  4. package/dist/cjs/core-sdk.js.map +1 -0
  5. package/dist/cjs/erc20/handler.d.ts +1 -0
  6. package/dist/cjs/erc20/handler.d.ts.map +1 -0
  7. package/dist/cjs/erc20/handler.js +1 -0
  8. package/dist/cjs/erc20/handler.js.map +1 -0
  9. package/dist/cjs/erc20/index.d.ts +1 -0
  10. package/dist/cjs/erc20/index.d.ts.map +1 -0
  11. package/dist/cjs/erc20/index.js +1 -0
  12. package/dist/cjs/erc20/index.js.map +1 -0
  13. package/dist/cjs/erc20/interface.d.ts +1 -0
  14. package/dist/cjs/erc20/interface.d.ts.map +1 -0
  15. package/dist/cjs/erc20/interface.js +1 -0
  16. package/dist/cjs/erc20/interface.js.map +1 -0
  17. package/dist/cjs/index.d.ts +1 -0
  18. package/dist/cjs/index.d.ts.map +1 -0
  19. package/dist/cjs/index.js +1 -0
  20. package/dist/cjs/index.js.map +1 -0
  21. package/dist/cjs/offers/handler.d.ts +1 -0
  22. package/dist/cjs/offers/handler.d.ts.map +1 -0
  23. package/dist/cjs/offers/handler.js +1 -0
  24. package/dist/cjs/offers/handler.js.map +1 -0
  25. package/dist/cjs/offers/index.d.ts +53 -52
  26. package/dist/cjs/offers/index.d.ts.map +1 -0
  27. package/dist/cjs/offers/index.js +1 -0
  28. package/dist/cjs/offers/index.js.map +1 -0
  29. package/dist/cjs/offers/interface.d.ts +2 -1
  30. package/dist/cjs/offers/interface.d.ts.map +1 -0
  31. package/dist/cjs/offers/interface.js +1 -0
  32. package/dist/cjs/offers/interface.js.map +1 -0
  33. package/dist/cjs/offers/subgraph.d.ts +1 -0
  34. package/dist/cjs/offers/subgraph.d.ts.map +1 -0
  35. package/dist/cjs/offers/subgraph.js +1 -0
  36. package/dist/cjs/offers/subgraph.js.map +1 -0
  37. package/dist/cjs/offers/types.d.ts +1 -0
  38. package/dist/cjs/offers/types.d.ts.map +1 -0
  39. package/dist/cjs/offers/types.js +1 -0
  40. package/dist/cjs/offers/types.js.map +1 -0
  41. package/dist/cjs/utils/errors.d.ts +1 -0
  42. package/dist/cjs/utils/errors.d.ts.map +1 -0
  43. package/dist/cjs/utils/errors.js +1 -0
  44. package/dist/cjs/utils/errors.js.map +1 -0
  45. package/dist/cjs/utils/subgraph.d.ts +1 -0
  46. package/dist/cjs/utils/subgraph.d.ts.map +1 -0
  47. package/dist/cjs/utils/subgraph.js +1 -0
  48. package/dist/cjs/utils/subgraph.js.map +1 -0
  49. package/dist/esm/core-sdk.d.ts +1 -0
  50. package/dist/esm/core-sdk.d.ts.map +1 -0
  51. package/dist/esm/core-sdk.js +1 -0
  52. package/dist/esm/core-sdk.js.map +1 -0
  53. package/dist/esm/erc20/handler.d.ts +1 -0
  54. package/dist/esm/erc20/handler.d.ts.map +1 -0
  55. package/dist/esm/erc20/handler.js +1 -0
  56. package/dist/esm/erc20/handler.js.map +1 -0
  57. package/dist/esm/erc20/index.d.ts +1 -0
  58. package/dist/esm/erc20/index.d.ts.map +1 -0
  59. package/dist/esm/erc20/index.js +1 -0
  60. package/dist/esm/erc20/index.js.map +1 -0
  61. package/dist/esm/erc20/interface.d.ts +1 -0
  62. package/dist/esm/erc20/interface.d.ts.map +1 -0
  63. package/dist/esm/erc20/interface.js +1 -0
  64. package/dist/esm/erc20/interface.js.map +1 -0
  65. package/dist/esm/index.d.ts +1 -0
  66. package/dist/esm/index.d.ts.map +1 -0
  67. package/dist/esm/index.js +1 -0
  68. package/dist/esm/index.js.map +1 -0
  69. package/dist/esm/offers/handler.d.ts +1 -0
  70. package/dist/esm/offers/handler.d.ts.map +1 -0
  71. package/dist/esm/offers/handler.js +1 -0
  72. package/dist/esm/offers/handler.js.map +1 -0
  73. package/dist/esm/offers/index.d.ts +53 -52
  74. package/dist/esm/offers/index.d.ts.map +1 -0
  75. package/dist/esm/offers/index.js +1 -0
  76. package/dist/esm/offers/index.js.map +1 -0
  77. package/dist/esm/offers/interface.d.ts +2 -1
  78. package/dist/esm/offers/interface.d.ts.map +1 -0
  79. package/dist/esm/offers/interface.js +1 -0
  80. package/dist/esm/offers/interface.js.map +1 -0
  81. package/dist/esm/offers/subgraph.d.ts +1 -0
  82. package/dist/esm/offers/subgraph.d.ts.map +1 -0
  83. package/dist/esm/offers/subgraph.js +1 -0
  84. package/dist/esm/offers/subgraph.js.map +1 -0
  85. package/dist/esm/offers/types.d.ts +1 -0
  86. package/dist/esm/offers/types.d.ts.map +1 -0
  87. package/dist/esm/offers/types.js +1 -0
  88. package/dist/esm/offers/types.js.map +1 -0
  89. package/dist/esm/utils/errors.d.ts +1 -0
  90. package/dist/esm/utils/errors.d.ts.map +1 -0
  91. package/dist/esm/utils/errors.js +1 -0
  92. package/dist/esm/utils/errors.js.map +1 -0
  93. package/dist/esm/utils/subgraph.d.ts +1 -0
  94. package/dist/esm/utils/subgraph.d.ts.map +1 -0
  95. package/dist/esm/utils/subgraph.js +1 -0
  96. package/dist/esm/utils/subgraph.js.map +1 -0
  97. package/package.json +5 -4
  98. package/src/core-sdk.ts +170 -0
  99. package/src/erc20/handler.ts +69 -0
  100. package/src/erc20/index.ts +2 -0
  101. package/src/erc20/interface.ts +4 -0
  102. package/src/index.ts +11 -0
  103. package/src/offers/handler.ts +80 -0
  104. package/src/offers/index.ts +12 -0
  105. package/src/offers/interface.ts +59 -0
  106. package/src/offers/subgraph.ts +105 -0
  107. package/src/offers/types.ts +34 -0
  108. package/src/utils/errors.ts +14 -0
  109. package/src/utils/subgraph.ts +43 -0
@@ -4,64 +4,65 @@ export * as iface from "./interface";
4
4
  export * from "./types";
5
5
  export declare const validation: {
6
6
  createOfferArgsSchema: import("yup/lib/object").OptionalObjectSchema<{
7
- price: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
8
- deposit: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
9
- penalty: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
10
- quantity: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
11
- validFromDateInMS: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
12
- validUntilDateInMS: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
13
- redeemableDateInMS: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
14
- fulfillmentPeriodDurationInMS: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
15
- voucherValidDurationInMS: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
16
- seller: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
17
- exchangeToken: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
18
- metadataUri: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
19
- metadataHash: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
7
+ price: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
8
+ deposit: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
9
+ penalty: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
10
+ quantity: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
11
+ validFromDateInMS: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
12
+ validUntilDateInMS: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
13
+ redeemableDateInMS: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
14
+ fulfillmentPeriodDurationInMS: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
15
+ voucherValidDurationInMS: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
16
+ seller: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
17
+ exchangeToken: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
18
+ metadataUri: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
19
+ metadataHash: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
20
20
  }, import("yup/lib/object").AnyObject, import("yup/lib/object").TypeOfShape<{
21
- price: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
22
- deposit: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
23
- penalty: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
24
- quantity: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
25
- validFromDateInMS: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
26
- validUntilDateInMS: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
27
- redeemableDateInMS: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
28
- fulfillmentPeriodDurationInMS: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
29
- voucherValidDurationInMS: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
30
- seller: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
31
- exchangeToken: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
32
- metadataUri: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
33
- metadataHash: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
21
+ price: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
22
+ deposit: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
23
+ penalty: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
24
+ quantity: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
25
+ validFromDateInMS: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
26
+ validUntilDateInMS: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
27
+ redeemableDateInMS: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
28
+ fulfillmentPeriodDurationInMS: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
29
+ voucherValidDurationInMS: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
30
+ seller: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
31
+ exchangeToken: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
32
+ metadataUri: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
33
+ metadataHash: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
34
34
  }>>;
35
35
  baseMetadataSchema: import("yup/lib/object").OptionalObjectSchema<{
36
- name: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
37
- description: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
38
- externalUrl: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
39
- schemaUrl: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
40
- type: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
36
+ name: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
37
+ description: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
38
+ externalUrl: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
39
+ schemaUrl: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
40
+ type: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
41
41
  }, import("yup/lib/object").AnyObject, import("yup/lib/object").TypeOfShape<{
42
- name: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
43
- description: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
44
- externalUrl: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
45
- schemaUrl: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
46
- type: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
42
+ name: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
43
+ description: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
44
+ externalUrl: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
45
+ schemaUrl: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
46
+ type: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
47
47
  }>>;
48
48
  productV1MetadataSchema: import("yup/lib/object").OptionalObjectSchema<{
49
- images: import("yup/lib/array").OptionalArraySchema<import("yup").StringSchema<string | undefined, import("yup/lib/types").AnyObject, string | undefined>, any, (string | undefined)[] | undefined>;
50
- tags: import("yup/lib/array").OptionalArraySchema<import("yup").StringSchema<string | undefined, import("yup/lib/types").AnyObject, string | undefined>, any, (string | undefined)[] | undefined>;
51
- brandName: import("yup").StringSchema<string | undefined, import("yup/lib/types").AnyObject, string | undefined>;
52
- name: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
53
- description: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
54
- externalUrl: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
55
- schemaUrl: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
56
- type: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
49
+ images: import("yup/lib/array").OptionalArraySchema<import("yup").StringSchema<string, import("yup/lib/types").AnyObject, string>, any, string[]>;
50
+ tags: import("yup/lib/array").OptionalArraySchema<import("yup").StringSchema<string, import("yup/lib/types").AnyObject, string>, any, string[]>;
51
+ brandName: import("yup").StringSchema<string, import("yup/lib/types").AnyObject, string>;
52
+ name: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
53
+ description: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
54
+ externalUrl: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
55
+ schemaUrl: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
56
+ type: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
57
57
  }, import("yup/lib/object").AnyObject, import("yup/lib/object").TypeOfShape<{
58
- images: import("yup/lib/array").OptionalArraySchema<import("yup").StringSchema<string | undefined, import("yup/lib/types").AnyObject, string | undefined>, any, (string | undefined)[] | undefined>;
59
- tags: import("yup/lib/array").OptionalArraySchema<import("yup").StringSchema<string | undefined, import("yup/lib/types").AnyObject, string | undefined>, any, (string | undefined)[] | undefined>;
60
- brandName: import("yup").StringSchema<string | undefined, import("yup/lib/types").AnyObject, string | undefined>;
61
- name: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
62
- description: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
63
- externalUrl: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
64
- schemaUrl: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
65
- type: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
58
+ images: import("yup/lib/array").OptionalArraySchema<import("yup").StringSchema<string, import("yup/lib/types").AnyObject, string>, any, string[]>;
59
+ tags: import("yup/lib/array").OptionalArraySchema<import("yup").StringSchema<string, import("yup/lib/types").AnyObject, string>, any, string[]>;
60
+ brandName: import("yup").StringSchema<string, import("yup/lib/types").AnyObject, string>;
61
+ name: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
62
+ description: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
63
+ externalUrl: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
64
+ schemaUrl: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
65
+ type: import("yup/lib/string").RequiredStringSchema<string, import("yup/lib/types").AnyObject>;
66
66
  }>>;
67
67
  };
68
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/offers/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,KAAK,MAAM,aAAa,CAAC;AACrC,cAAc,SAAS,CAAC;AAExB,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAItB,CAAC"}
@@ -8,3 +8,4 @@ export const validation = {
8
8
  baseMetadataSchema: utils.validation.baseMetadataSchema,
9
9
  productV1MetadataSchema: utils.validation.productV1MetadataSchema
10
10
  };
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/offers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAE9C,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,KAAK,MAAM,aAAa,CAAC;AACrC,cAAc,SAAS,CAAC;AAExB,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,qBAAqB,EAAE,KAAK,CAAC,UAAU,CAAC,qBAAqB;IAC7D,kBAAkB,EAAE,KAAK,CAAC,UAAU,CAAC,kBAAkB;IACvD,uBAAuB,EAAE,KAAK,CAAC,UAAU,CAAC,uBAAuB;CAClE,CAAC"}
@@ -2,7 +2,8 @@ import { OfferStruct, Log } from "@bosonprotocol/common";
2
2
  import { Interface } from "@ethersproject/abi";
3
3
  import { CreateOfferArgs } from "./types";
4
4
  export declare const bosonOfferHandlerIface: Interface;
5
- export declare function getCreatedOfferIdFromLogs(logs: Log[]): string | null;
5
+ export declare function getCreatedOfferIdFromLogs(logs: Log[]): string;
6
6
  export declare function parseLog(data: string, topics: string[]): import("@ethersproject/abi").LogDescription;
7
7
  export declare function encodeCreateOffer(args: CreateOfferArgs): string;
8
8
  export declare function createOfferArgsToStruct(args: CreateOfferArgs): Partial<OfferStruct>;
9
+ //# sourceMappingURL=interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/offers/interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAe,GAAG,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,eAAO,MAAM,sBAAsB,WAA4C,CAAC;AAEhF,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,GAAG,EAAE,UAYpD;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,+CAEtD;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,eAAe,UAItD;AAED,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,eAAe,GACpB,OAAO,CAAC,WAAW,CAAC,CAyBtB"}
@@ -32,3 +32,4 @@ export function createOfferArgsToStruct(args) {
32
32
  voucherValidDuration: utils.timestamp.msToSec(voucherValidDurationInMS)
33
33
  };
34
34
  }
35
+ //# sourceMappingURL=interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interface.js","sourceRoot":"","sources":["../../../src/offers/interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,EAAE,IAAI,EAAO,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGpD,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,SAAS,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;AAEhF,MAAM,UAAU,yBAAyB,CAAC,IAAW;IACnD,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IAErE,MAAM,CAAC,eAAe,CAAC,GAAG,UAAU,CAAC,MAAM,CACzC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,cAAc,CACrC,CAAC;IAEF,IAAI,CAAC,eAAe,EAAE;QACpB,OAAO,IAAI,CAAC;KACb;IAED,OAAO,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAC9C,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,MAAgB;IACrD,OAAO,sBAAsB,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;AAC3D,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,IAAqB;IACrD,OAAO,sBAAsB,CAAC,kBAAkB,CAAC,aAAa,EAAE;QAC9D,uBAAuB,CAAC,IAAI,CAAC;KAC9B,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,uBAAuB,CACrC,IAAqB;IAErB,MAAM,EACJ,aAAa,EACb,MAAM,EACN,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,6BAA6B,EAC7B,wBAAwB,EACxB,GAAG,QAAQ,EACZ,GAAG,IAAI,CAAC;IAET,OAAO;QACL,EAAE,EAAE,GAAG;QACP,GAAG,QAAQ;QACX,aAAa,EAAE,UAAU,CAAC,aAAa,CAAC;QACxC,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC;QAC1B,aAAa,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,iBAAiB,CAAC;QACzD,cAAc,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,kBAAkB,CAAC;QAC3D,cAAc,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,kBAAkB,CAAC;QAC3D,yBAAyB,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,CAChD,6BAA6B,CAC9B;QACD,oBAAoB,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,wBAAwB,CAAC;KACxE,CAAC;AACJ,CAAC"}
@@ -6,3 +6,4 @@ export declare const getOfferByIdQuery: string;
6
6
  export declare function getOfferById(subgraphUrl: string, offerId: BigNumberish): Promise<RawOfferFromSubgraph>;
7
7
  export declare const getAllOffersOfSellerQuery: string;
8
8
  export declare function getAllOffersOfSeller(subgraphUrl: string, sellerAddress: string, opts?: MultiQueryOpts): Promise<RawOfferFromSubgraph[]>;
9
+ //# sourceMappingURL=subgraph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subgraph.d.ts","sourceRoot":"","sources":["../../../src/offers/subgraph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAiB,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAE/C,eAAO,MAAM,mBAAmB,8bAiC/B,CAAC;AAEF,eAAO,MAAM,iBAAiB,QAO7B,CAAC;AAEF,wBAAsB,YAAY,CAChC,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,oBAAoB,CAAC,CAQ/B;AAED,eAAO,MAAM,yBAAyB,QAoBrC,CAAC;AAEF,wBAAsB,oBAAoB,CACxC,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,MAAM,EACrB,IAAI,GAAE,cAAmB,GACxB,OAAO,CAAC,oBAAoB,EAAE,CAAC,CAiBjC"}
@@ -80,3 +80,4 @@ export async function getAllOffersOfSeller(subgraphUrl, sellerAddress, opts = {}
80
80
  }
81
81
  return seller.offers;
82
82
  }
83
+ //# sourceMappingURL=subgraph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subgraph.js","sourceRoot":"","sources":["../../../src/offers/subgraph.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAkB,MAAM,mBAAmB,CAAC;AAGlE,MAAM,CAAC,MAAM,mBAAmB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiClC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG;;;;;;EAM/B,mBAAmB;CACpB,CAAC;AAEF,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,WAAmB,EACnB,OAAqB;IAErB,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,aAAa,CACnC,WAAW,EACX,iBAAiB,EACjB,EAAE,OAAO,EAAE,OAAO,CAAC,QAAQ,EAAE,EAAE,CAChC,CAAC;IAEF,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,CAAC,MAAM,yBAAyB,GAAG;;;;;;;;;;;;;;;;;;;EAmBvC,mBAAmB;CACpB,CAAC;AAEF,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,WAAmB,EACnB,aAAqB,EACrB,OAAuB,EAAE;IAEzB,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,aAAa,CAEnC,WAAW,EAAE,yBAAyB,EAAE;QACzC,MAAM,EAAE,aAAa,CAAC,WAAW,EAAE;QACnC,KAAK,EAAE,GAAG;QACV,IAAI,EAAE,CAAC;QACP,OAAO,EAAE,WAAW;QACpB,cAAc,EAAE,MAAM;QACtB,GAAG,IAAI;KACR,CAAC,CAAC;IAEH,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,EAAE,CAAC;KACX;IAED,OAAO,MAAM,CAAC,MAAM,CAAC;AACvB,CAAC"}
@@ -31,3 +31,4 @@ export declare type RawOfferFromSubgraph = {
31
31
  type: string;
32
32
  };
33
33
  };
34
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/offers/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,oBAAY,oBAAoB,GAAG;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,yBAAyB,EAAE,MAAM,CAAC;IAClC,oBAAoB,EAAE,MAAM,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,IAAI,GAAG,MAAM,CAAC;IACxB,MAAM,EAAE;QACN,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,aAAa,EAAE;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,QAAQ,EAAE,IAAI,GAAG;QACf,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,EAAE,MAAM,CAAC;QACpB,SAAS,EAAE,MAAM,CAAC;QAClB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH,CAAC"}
@@ -1 +1,2 @@
1
1
  export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/offers/types.ts"],"names":[],"mappings":""}
@@ -7,3 +7,4 @@ export declare class FetchError extends Error {
7
7
  statusText?: string;
8
8
  });
9
9
  }
10
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/utils/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,UAAW,SAAQ,KAAK;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;gBAER,IAAI,EAAE;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB;CAKF"}
@@ -7,3 +7,4 @@ export class FetchError extends Error {
7
7
  this.statusText = args.statusText;
8
8
  }
9
9
  }
10
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/utils/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,UAAW,SAAQ,KAAK;IACnC,UAAU,CAAU;IACpB,UAAU,CAAU;IAEpB,YAAY,IAIX;QACC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QAClC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;IACpC,CAAC;CACF"}
@@ -5,3 +5,4 @@ export declare type MultiQueryOpts = Partial<{
5
5
  orderDirection: "asc" | "desc";
6
6
  }>;
7
7
  export declare function fetchSubgraph<T>(subgraphUrl: string, query: string, variables?: Record<string, unknown>): Promise<T>;
8
+ //# sourceMappingURL=subgraph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subgraph.d.ts","sourceRoot":"","sources":["../../../src/utils/subgraph.ts"],"names":[],"mappings":"AAGA,oBAAY,cAAc,GAAG,OAAO,CAAC;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,KAAK,GAAG,MAAM,CAAC;CAChC,CAAC,CAAC;AAEH,wBAAsB,aAAa,CAAC,CAAC,EACnC,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,EACb,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAClC,OAAO,CAAC,CAAC,CAAC,CA4BZ"}
@@ -25,3 +25,4 @@ export async function fetchSubgraph(subgraphUrl, query, variables) {
25
25
  }
26
26
  return data;
27
27
  }
28
+ //# sourceMappingURL=subgraph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subgraph.js","sourceRoot":"","sources":["../../../src/utils/subgraph.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,aAAa,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAStC,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,WAAmB,EACnB,KAAa,EACb,SAAmC;IAEnC,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,WAAW,EAAE;QACxC,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;SACnC;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;YACnB,KAAK;YACL,SAAS;SACV,CAAC;KACH,CAAC,CAAC;IAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;QAChB,MAAM,IAAI,UAAU,CAAC;YACnB,OAAO,EAAE,oBAAoB,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE;YACrE,UAAU,EAAE,QAAQ,CAAC,MAAM;YAC3B,UAAU,EAAE,QAAQ,CAAC,UAAU;SAChC,CAAC,CAAC;KACJ;IAED,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IACnC,MAAM,EAAE,IAAI,GAAG,EAAE,EAAE,MAAM,GAAG,EAAE,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC;IAE9C,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;QACrB,MAAM,IAAI,KAAK,CAAC,mBAAmB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;KAC9D;IAED,OAAO,IAAS,CAAC;AACnB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bosonprotocol/core-sdk",
3
- "version": "1.1.0",
3
+ "version": "1.1.1-alpha.0",
4
4
  "description": "> TODO: description",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -23,13 +23,14 @@
23
23
  },
24
24
  "homepage": "https://github.com/bosonprotocol/core-components/tree/main/packages/contracts-sdk#readme",
25
25
  "files": [
26
- "dist/*"
26
+ "dist/*",
27
+ "src/*"
27
28
  ],
28
29
  "publishConfig": {
29
30
  "access": "restricted"
30
31
  },
31
32
  "dependencies": {
32
- "@bosonprotocol/common": "1.1.0",
33
+ "@bosonprotocol/common": "1.1.1-alpha.0",
33
34
  "@ethersproject/abi": "^5.5.0",
34
35
  "@ethersproject/address": "^5.5.0",
35
36
  "@ethersproject/bignumber": "^5.5.0",
@@ -45,5 +46,5 @@
45
46
  "ts-jest": "^27.1.3",
46
47
  "typescript": "^4.5.5"
47
48
  },
48
- "gitHead": "a01cf4ce35fc49b82f0182b38b25d77baf331a54"
49
+ "gitHead": "63d79a2cf5a6eb051406d1387437723d62087b50"
49
50
  }
@@ -0,0 +1,170 @@
1
+ import {
2
+ Web3LibAdapter,
3
+ TransactionResponse,
4
+ getDefaultConfig,
5
+ MetadataStorage,
6
+ AnyMetadata,
7
+ Log
8
+ } from "@bosonprotocol/common";
9
+ import { BigNumberish } from "@ethersproject/bignumber";
10
+ import * as offers from "./offers";
11
+ import * as erc20 from "./erc20";
12
+ import { MultiQueryOpts } from "./utils/subgraph";
13
+
14
+ export class CoreSDK {
15
+ private _web3Lib: Web3LibAdapter;
16
+ private _metadataStorage?: MetadataStorage;
17
+ private _theGraphStorage?: MetadataStorage;
18
+
19
+ private _subgraphUrl: string;
20
+ private _protocolDiamond: string;
21
+
22
+ constructor(opts: {
23
+ web3Lib: Web3LibAdapter;
24
+ subgraphUrl: string;
25
+ protocolDiamond: string;
26
+ metadataStorage?: MetadataStorage;
27
+ theGraphStorage?: MetadataStorage;
28
+ }) {
29
+ this._web3Lib = opts.web3Lib;
30
+ this._subgraphUrl = opts.subgraphUrl;
31
+ this._protocolDiamond = opts.protocolDiamond;
32
+ this._metadataStorage = opts.metadataStorage;
33
+ this._theGraphStorage = opts.theGraphStorage;
34
+ }
35
+
36
+ static fromDefaultConfig(args: {
37
+ web3Lib: Web3LibAdapter;
38
+ envName?: string;
39
+ chainId?: number;
40
+ metadataStorage?: MetadataStorage;
41
+ theGraphStorage?: MetadataStorage;
42
+ }) {
43
+ const defaultConfig = getDefaultConfig({
44
+ envName: args.envName,
45
+ chainId: args.chainId
46
+ });
47
+
48
+ return new CoreSDK({
49
+ web3Lib: args.web3Lib,
50
+ metadataStorage: args.metadataStorage,
51
+ theGraphStorage: args.theGraphStorage,
52
+ subgraphUrl: defaultConfig.subgraphUrl,
53
+ protocolDiamond: defaultConfig.contracts.protocolDiamond
54
+ });
55
+ }
56
+
57
+ public async storeMetadata(metadata: AnyMetadata): Promise<string> {
58
+ if (!this._metadataStorage) {
59
+ throw new Error("No metadata storage set");
60
+ }
61
+
62
+ return this._metadataStorage.storeMetadata(metadata);
63
+ }
64
+
65
+ public async getMetadata(metadataHashOrUri: string): Promise<AnyMetadata> {
66
+ if (!this._metadataStorage) {
67
+ throw new Error("No metadata storage set");
68
+ }
69
+
70
+ return this._metadataStorage.getMetadata(metadataHashOrUri);
71
+ }
72
+
73
+ public async createOffer(
74
+ offerToCreate: offers.CreateOfferArgs,
75
+ overrides: Partial<{
76
+ contractAddress: string;
77
+ }> = {}
78
+ ): Promise<TransactionResponse> {
79
+ return offers.handler.createOffer({
80
+ offerToCreate,
81
+ web3Lib: this._web3Lib,
82
+ theGraphStorage: this._theGraphStorage,
83
+ metadataStorage: this._metadataStorage,
84
+ contractAddress: overrides.contractAddress || this._protocolDiamond
85
+ });
86
+ }
87
+
88
+ public getCreatedOfferIdFromLogs(logs: Log[]): string | null {
89
+ return offers.iface.getCreatedOfferIdFromLogs(logs);
90
+ }
91
+
92
+ public async voidOffer(
93
+ offerId: BigNumberish,
94
+ overrides: Partial<{
95
+ contractAddress: string;
96
+ }> = {}
97
+ ): Promise<TransactionResponse> {
98
+ return offers.handler.voidOffer({
99
+ offerId,
100
+ web3Lib: this._web3Lib,
101
+ subgraphUrl: this._subgraphUrl,
102
+ contractAddress: overrides.contractAddress || this._protocolDiamond
103
+ });
104
+ }
105
+
106
+ public async getOfferById(
107
+ offerId: BigNumberish
108
+ ): Promise<offers.RawOfferFromSubgraph> {
109
+ return offers.subgraph.getOfferById(this._subgraphUrl, offerId);
110
+ }
111
+
112
+ public async getAllOffersOfSeller(
113
+ sellerAddress: string,
114
+ opts: MultiQueryOpts = {}
115
+ ): Promise<offers.RawOfferFromSubgraph[]> {
116
+ return offers.subgraph.getAllOffersOfSeller(
117
+ this._subgraphUrl,
118
+ sellerAddress,
119
+ opts
120
+ );
121
+ }
122
+
123
+ public async getExchangeTokenAllowance(
124
+ exchangeToken: string,
125
+ overrides: Partial<{
126
+ spender: string;
127
+ owner: string;
128
+ }> = {}
129
+ ): Promise<string> {
130
+ return erc20.handler.getAllowance({
131
+ web3Lib: this._web3Lib,
132
+ contractAddress: exchangeToken,
133
+ spender: overrides.spender || this._protocolDiamond,
134
+ owner: overrides.owner || (await this._web3Lib.getSignerAddress())
135
+ });
136
+ }
137
+
138
+ public async getExchangeTokenInfo(exchangeToken: string): Promise<{
139
+ name: string;
140
+ decimals: number;
141
+ symbol: string;
142
+ }> {
143
+ const args = {
144
+ web3Lib: this._web3Lib,
145
+ contractAddress: exchangeToken
146
+ };
147
+ const [decimals, name, symbol] = await Promise.all([
148
+ erc20.handler.getDecimals(args),
149
+ erc20.handler.getName(args),
150
+ erc20.handler.getSymbol(args)
151
+ ]);
152
+
153
+ return { decimals, name, symbol };
154
+ }
155
+
156
+ public async approveExchangeToken(
157
+ exchangeToken: string,
158
+ value: BigNumberish,
159
+ overrides: Partial<{
160
+ spender: string;
161
+ }> = {}
162
+ ): Promise<TransactionResponse> {
163
+ return erc20.handler.approve({
164
+ contractAddress: exchangeToken,
165
+ spender: overrides.spender || this._protocolDiamond,
166
+ value,
167
+ web3Lib: this._web3Lib
168
+ });
169
+ }
170
+ }
@@ -0,0 +1,69 @@
1
+ import { Web3LibAdapter } from "@bosonprotocol/common";
2
+ import { BigNumberish } from "@ethersproject/bignumber";
3
+ import { erc20Iface } from "./interface";
4
+
5
+ export async function approve(args: {
6
+ contractAddress: string;
7
+ spender: string;
8
+ value: BigNumberish;
9
+ web3Lib: Web3LibAdapter;
10
+ }) {
11
+ return args.web3Lib.sendTransaction({
12
+ to: args.contractAddress,
13
+ data: erc20Iface.encodeFunctionData("approve", [args.spender, args.value])
14
+ });
15
+ }
16
+
17
+ export async function getAllowance(args: {
18
+ contractAddress: string;
19
+ owner: string;
20
+ spender: string;
21
+ web3Lib: Web3LibAdapter;
22
+ }) {
23
+ const result = await args.web3Lib.call({
24
+ to: args.contractAddress,
25
+ data: erc20Iface.encodeFunctionData("allowance", [args.owner, args.spender])
26
+ });
27
+
28
+ const [allowance] = erc20Iface.decodeFunctionResult("allowance", result);
29
+ return String(allowance);
30
+ }
31
+
32
+ export async function getDecimals(args: {
33
+ contractAddress: string;
34
+ web3Lib: Web3LibAdapter;
35
+ }) {
36
+ const result = await args.web3Lib.call({
37
+ to: args.contractAddress,
38
+ data: erc20Iface.encodeFunctionData("decimals", [])
39
+ });
40
+
41
+ const [decimals] = erc20Iface.decodeFunctionResult("decimals", result);
42
+ return Number(decimals);
43
+ }
44
+
45
+ export async function getSymbol(args: {
46
+ contractAddress: string;
47
+ web3Lib: Web3LibAdapter;
48
+ }) {
49
+ const result = await args.web3Lib.call({
50
+ to: args.contractAddress,
51
+ data: erc20Iface.encodeFunctionData("symbol", [])
52
+ });
53
+
54
+ const [symbols] = erc20Iface.decodeFunctionResult("symbol", result);
55
+ return String(symbols);
56
+ }
57
+
58
+ export async function getName(args: {
59
+ contractAddress: string;
60
+ web3Lib: Web3LibAdapter;
61
+ }) {
62
+ const result = await args.web3Lib.call({
63
+ to: args.contractAddress,
64
+ data: erc20Iface.encodeFunctionData("name", [])
65
+ });
66
+
67
+ const [name] = erc20Iface.decodeFunctionResult("name", result);
68
+ return String(name);
69
+ }
@@ -0,0 +1,2 @@
1
+ export * as handler from "./handler";
2
+ export * as iface from "./interface";
@@ -0,0 +1,4 @@
1
+ import { abis } from "@bosonprotocol/common";
2
+ import { Interface } from "@ethersproject/abi";
3
+
4
+ export const erc20Iface = new Interface(abis.ERC20ABI);
package/src/index.ts ADDED
@@ -0,0 +1,11 @@
1
+ export { CoreSDK } from "./core-sdk";
2
+
3
+ export * as offers from "./offers";
4
+ export * as erc20 from "./erc20";
5
+
6
+ export {
7
+ defaultConfigs,
8
+ getDefaultConfig,
9
+ MetadataType,
10
+ AnyMetadata
11
+ } from "@bosonprotocol/common";
@@ -0,0 +1,80 @@
1
+ import { BigNumberish } from "@ethersproject/bignumber";
2
+ import {
3
+ Web3LibAdapter,
4
+ TransactionResponse,
5
+ MetadataStorage,
6
+ utils
7
+ } from "@bosonprotocol/common";
8
+ import { bosonOfferHandlerIface, encodeCreateOffer } from "./interface";
9
+ import { getOfferById } from "./subgraph";
10
+ import { CreateOfferArgs } from "./types";
11
+
12
+ export async function createOffer(args: {
13
+ offerToCreate: CreateOfferArgs;
14
+ contractAddress: string;
15
+ web3Lib: Web3LibAdapter;
16
+ metadataStorage?: MetadataStorage;
17
+ theGraphStorage?: MetadataStorage;
18
+ }): Promise<TransactionResponse> {
19
+ await utils.validation.createOfferArgsSchema.validate(args.offerToCreate, {
20
+ abortEarly: false
21
+ });
22
+
23
+ // We use the feature `ipfsOnEthereum` in our subgraph to resolve metadata from IPFS
24
+ // and store them in the graph. In order for the graph node to reliably resolve them,
25
+ // we need to add the metadata additionally to the IPFS node of the graph.
26
+ // See https://thegraph.com/docs/en/developer/assemblyscript-api/#ipfs-api
27
+ if (args.metadataStorage && args.theGraphStorage) {
28
+ await storeMetadataOnTheGraph({
29
+ metadataUriOrHash: args.offerToCreate.metadataHash,
30
+ metadataStorage: args.metadataStorage,
31
+ theGraphStorage: args.theGraphStorage
32
+ });
33
+ }
34
+
35
+ return args.web3Lib.sendTransaction({
36
+ to: args.contractAddress,
37
+ data: encodeCreateOffer(args.offerToCreate)
38
+ });
39
+ }
40
+
41
+ export async function voidOffer(args: {
42
+ contractAddress: string;
43
+ subgraphUrl: string;
44
+ offerId: BigNumberish;
45
+ web3Lib: Web3LibAdapter;
46
+ }): Promise<TransactionResponse> {
47
+ const offer = await getOfferById(args.subgraphUrl, args.offerId);
48
+
49
+ if (!offer) {
50
+ throw new Error(`Offer with id "${args.offerId}" does not exist`);
51
+ }
52
+
53
+ if (offer.voidedAt) {
54
+ throw new Error(`Offer with id "${args.offerId}" is already voided`);
55
+ }
56
+
57
+ const signerAddress = await args.web3Lib.getSignerAddress();
58
+ if (offer.seller.address.toLowerCase() !== signerAddress.toLowerCase()) {
59
+ throw new Error(
60
+ `Signer with address "${signerAddress}" is not the seller "${offer.seller.address}"`
61
+ );
62
+ }
63
+
64
+ return args.web3Lib.sendTransaction({
65
+ to: args.contractAddress,
66
+ data: bosonOfferHandlerIface.encodeFunctionData("voidOffer", [args.offerId])
67
+ });
68
+ }
69
+
70
+ export async function storeMetadataOnTheGraph(args: {
71
+ metadataUriOrHash: string;
72
+ metadataStorage: MetadataStorage;
73
+ theGraphStorage: MetadataStorage;
74
+ }): Promise<string> {
75
+ const metadata = await args.metadataStorage.getMetadata(
76
+ args.metadataUriOrHash
77
+ );
78
+ const metadataUri = await args.theGraphStorage.storeMetadata(metadata);
79
+ return metadataUri;
80
+ }