@bosonprotocol/core-sdk 1.1.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 (51) hide show
  1. package/LICENSE.md +192 -0
  2. package/README.md +117 -0
  3. package/dist/cjs/core-sdk.d.ts +48 -0
  4. package/dist/cjs/core-sdk.js +145 -0
  5. package/dist/cjs/erc20/handler.d.ts +26 -0
  6. package/dist/cjs/erc20/handler.js +66 -0
  7. package/dist/cjs/erc20/index.d.ts +2 -0
  8. package/dist/cjs/erc20/index.js +28 -0
  9. package/dist/cjs/erc20/interface.d.ts +2 -0
  10. package/dist/cjs/erc20/interface.js +6 -0
  11. package/dist/cjs/index.d.ts +4 -0
  12. package/dist/cjs/index.js +34 -0
  13. package/dist/cjs/offers/handler.d.ts +21 -0
  14. package/dist/cjs/offers/handler.js +66 -0
  15. package/dist/cjs/offers/index.d.ts +67 -0
  16. package/dist/cjs/offers/index.js +39 -0
  17. package/dist/cjs/offers/interface.d.ts +8 -0
  18. package/dist/cjs/offers/interface.js +42 -0
  19. package/dist/cjs/offers/subgraph.d.ts +8 -0
  20. package/dist/cjs/offers/subgraph.js +93 -0
  21. package/dist/cjs/offers/types.d.ts +33 -0
  22. package/dist/cjs/offers/types.js +2 -0
  23. package/dist/cjs/utils/errors.d.ts +9 -0
  24. package/dist/cjs/utils/errors.js +11 -0
  25. package/dist/cjs/utils/subgraph.d.ts +7 -0
  26. package/dist/cjs/utils/subgraph.js +45 -0
  27. package/dist/esm/core-sdk.d.ts +48 -0
  28. package/dist/esm/core-sdk.js +96 -0
  29. package/dist/esm/erc20/handler.d.ts +26 -0
  30. package/dist/esm/erc20/handler.js +39 -0
  31. package/dist/esm/erc20/index.d.ts +2 -0
  32. package/dist/esm/erc20/index.js +2 -0
  33. package/dist/esm/erc20/interface.d.ts +2 -0
  34. package/dist/esm/erc20/interface.js +3 -0
  35. package/dist/esm/index.d.ts +4 -0
  36. package/dist/esm/index.js +4 -0
  37. package/dist/esm/offers/handler.d.ts +21 -0
  38. package/dist/esm/offers/handler.js +45 -0
  39. package/dist/esm/offers/index.d.ts +67 -0
  40. package/dist/esm/offers/index.js +10 -0
  41. package/dist/esm/offers/interface.d.ts +8 -0
  42. package/dist/esm/offers/interface.js +34 -0
  43. package/dist/esm/offers/subgraph.d.ts +8 -0
  44. package/dist/esm/offers/subgraph.js +82 -0
  45. package/dist/esm/offers/types.d.ts +33 -0
  46. package/dist/esm/offers/types.js +1 -0
  47. package/dist/esm/utils/errors.d.ts +9 -0
  48. package/dist/esm/utils/errors.js +9 -0
  49. package/dist/esm/utils/subgraph.d.ts +7 -0
  50. package/dist/esm/utils/subgraph.js +27 -0
  51. package/package.json +49 -0
package/LICENSE.md ADDED
@@ -0,0 +1,192 @@
1
+ Copyright 2022 The Boson Protocol and contributors
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+
15
+ ```
16
+ Apache License
17
+ Version 2.0, January 2004
18
+ http://www.apache.org/licenses/
19
+
20
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
21
+
22
+ 1. Definitions.
23
+
24
+ "License" shall mean the terms and conditions for use, reproduction,
25
+ and distribution as defined by Sections 1 through 9 of this document.
26
+
27
+ "Licensor" shall mean the copyright owner or entity authorized by
28
+ the copyright owner that is granting the License.
29
+
30
+ "Legal Entity" shall mean the union of the acting entity and all
31
+ other entities that control, are controlled by, or are under common
32
+ control with that entity. For the purposes of this definition,
33
+ "control" means (i) the power, direct or indirect, to cause the
34
+ direction or management of such entity, whether by contract or
35
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
36
+ outstanding shares, or (iii) beneficial ownership of such entity.
37
+
38
+ "You" (or "Your") shall mean an individual or Legal Entity
39
+ exercising permissions granted by this License.
40
+
41
+ "Source" form shall mean the preferred form for making modifications,
42
+ including but not limited to software source code, documentation
43
+ source, and configuration files.
44
+
45
+ "Object" form shall mean any form resulting from mechanical
46
+ transformation or translation of a Source form, including but
47
+ not limited to compiled object code, generated documentation,
48
+ and conversions to other media types.
49
+
50
+ "Work" shall mean the work of authorship, whether in Source or
51
+ Object form, made available under the License, as indicated by a
52
+ copyright notice that is included in or attached to the work
53
+ (an example is provided in the Appendix below).
54
+
55
+ "Derivative Works" shall mean any work, whether in Source or Object
56
+ form, that is based on (or derived from) the Work and for which the
57
+ editorial revisions, annotations, elaborations, or other modifications
58
+ represent, as a whole, an original work of authorship. For the purposes
59
+ of this License, Derivative Works shall not include works that remain
60
+ separable from, or merely link (or bind by name) to the interfaces of,
61
+ the Work and Derivative Works thereof.
62
+
63
+ "Contribution" shall mean any work of authorship, including
64
+ the original version of the Work and any modifications or additions
65
+ to that Work or Derivative Works thereof, that is intentionally
66
+ submitted to Licensor for inclusion in the Work by the copyright owner
67
+ or by an individual or Legal Entity authorized to submit on behalf of
68
+ the copyright owner. For the purposes of this definition, "submitted"
69
+ means any form of electronic, verbal, or written communication sent
70
+ to the Licensor or its representatives, including but not limited to
71
+ communication on electronic mailing lists, source code control systems,
72
+ and issue tracking systems that are managed by, or on behalf of, the
73
+ Licensor for the purpose of discussing and improving the Work, but
74
+ excluding communication that is conspicuously marked or otherwise
75
+ designated in writing by the copyright owner as "Not a Contribution."
76
+
77
+ "Contributor" shall mean Licensor and any individual or Legal Entity
78
+ on behalf of whom a Contribution has been received by Licensor and
79
+ subsequently incorporated within the Work.
80
+
81
+ 2. Grant of Copyright License. Subject to the terms and conditions of
82
+ this License, each Contributor hereby grants to You a perpetual,
83
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
84
+ copyright license to reproduce, prepare Derivative Works of,
85
+ publicly display, publicly perform, sublicense, and distribute the
86
+ Work and such Derivative Works in Source or Object form.
87
+
88
+ 3. Grant of Patent License. Subject to the terms and conditions of
89
+ this License, each Contributor hereby grants to You a perpetual,
90
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
91
+ (except as stated in this section) patent license to make, have made,
92
+ use, offer to sell, sell, import, and otherwise transfer the Work,
93
+ where such license applies only to those patent claims licensable
94
+ by such Contributor that are necessarily infringed by their
95
+ Contribution(s) alone or by combination of their Contribution(s)
96
+ with the Work to which such Contribution(s) was submitted. If You
97
+ institute patent litigation against any entity (including a
98
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
99
+ or a Contribution incorporated within the Work constitutes direct
100
+ or contributory patent infringement, then any patent licenses
101
+ granted to You under this License for that Work shall terminate
102
+ as of the date such litigation is filed.
103
+
104
+ 4. Redistribution. You may reproduce and distribute copies of the
105
+ Work or Derivative Works thereof in any medium, with or without
106
+ modifications, and in Source or Object form, provided that You
107
+ meet the following conditions:
108
+
109
+ (a) You must give any other recipients of the Work or
110
+ Derivative Works a copy of this License; and
111
+
112
+ (b) You must cause any modified files to carry prominent notices
113
+ stating that You changed the files; and
114
+
115
+ (c) You must retain, in the Source form of any Derivative Works
116
+ that You distribute, all copyright, patent, trademark, and
117
+ attribution notices from the Source form of the Work,
118
+ excluding those notices that do not pertain to any part of
119
+ the Derivative Works; and
120
+
121
+ (d) If the Work includes a "NOTICE" text file as part of its
122
+ distribution, then any Derivative Works that You distribute must
123
+ include a readable copy of the attribution notices contained
124
+ within such NOTICE file, excluding those notices that do not
125
+ pertain to any part of the Derivative Works, in at least one
126
+ of the following places: within a NOTICE text file distributed
127
+ as part of the Derivative Works; within the Source form or
128
+ documentation, if provided along with the Derivative Works; or,
129
+ within a display generated by the Derivative Works, if and
130
+ wherever such third-party notices normally appear. The contents
131
+ of the NOTICE file are for informational purposes only and
132
+ do not modify the License. You may add Your own attribution
133
+ notices within Derivative Works that You distribute, alongside
134
+ or as an addendum to the NOTICE text from the Work, provided
135
+ that such additional attribution notices cannot be construed
136
+ as modifying the License.
137
+
138
+ You may add Your own copyright statement to Your modifications and
139
+ may provide additional or different license terms and conditions
140
+ for use, reproduction, or distribution of Your modifications, or
141
+ for any such Derivative Works as a whole, provided Your use,
142
+ reproduction, and distribution of the Work otherwise complies with
143
+ the conditions stated in this License.
144
+
145
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
146
+ any Contribution intentionally submitted for inclusion in the Work
147
+ by You to the Licensor shall be under the terms and conditions of
148
+ this License, without any additional terms or conditions.
149
+ Notwithstanding the above, nothing herein shall supersede or modify
150
+ the terms of any separate license agreement you may have executed
151
+ with Licensor regarding such Contributions.
152
+
153
+ 6. Trademarks. This License does not grant permission to use the trade
154
+ names, trademarks, service marks, or product names of the Licensor,
155
+ except as required for reasonable and customary use in describing the
156
+ origin of the Work and reproducing the content of the NOTICE file.
157
+
158
+ 7. Disclaimer of Warranty. Unless required by applicable law or
159
+ agreed to in writing, Licensor provides the Work (and each
160
+ Contributor provides its Contributions) on an "AS IS" BASIS,
161
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
162
+ implied, including, without limitation, any warranties or conditions
163
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
164
+ PARTICULAR PURPOSE. You are solely responsible for determining the
165
+ appropriateness of using or redistributing the Work and assume any
166
+ risks associated with Your exercise of permissions under this License.
167
+
168
+ 8. Limitation of Liability. In no event and under no legal theory,
169
+ whether in tort (including negligence), contract, or otherwise,
170
+ unless required by applicable law (such as deliberate and grossly
171
+ negligent acts) or agreed to in writing, shall any Contributor be
172
+ liable to You for damages, including any direct, indirect, special,
173
+ incidental, or consequential damages of any character arising as a
174
+ result of this License or out of the use or inability to use the
175
+ Work (including but not limited to damages for loss of goodwill,
176
+ work stoppage, computer failure or malfunction, or any and all
177
+ other commercial damages or losses), even if such Contributor
178
+ has been advised of the possibility of such damages.
179
+
180
+ 9. Accepting Warranty or Additional Liability. While redistributing
181
+ the Work or Derivative Works thereof, You may choose to offer,
182
+ and charge a fee for, acceptance of support, warranty, indemnity,
183
+ or other liability obligations and/or rights consistent with this
184
+ License. However, in accepting such obligations, You may act only
185
+ on Your own behalf and on Your sole responsibility, not on behalf
186
+ of any other Contributor, and only if You agree to indemnify,
187
+ defend, and hold each Contributor harmless for any liability
188
+ incurred by, or claims asserted against, such Contributor by reason
189
+ of your accepting any such warranty or additional liability.
190
+
191
+ END OF TERMS AND CONDITIONS
192
+ ```
package/README.md ADDED
@@ -0,0 +1,117 @@
1
+ # `@bosonprotocol/core-sdk`
2
+
3
+ JS lib that facilitates interaction with the Boson Protocol contracts, subgraph and metadata storage.
4
+
5
+ ## Install
6
+
7
+ The `core-sdk` is intended to be used in combination with implementations of the `Web3LibAdapter` and `MetadataStorage` interfaces.
8
+
9
+ If you, for example, want to use the `core-sdk` in combination with [`ethers`](https://docs.ethers.io/v5/) and `IPFS` as the metadata storage, then run
10
+
11
+ ```bash
12
+ npm i @bosonprotocol/core-sdk @bosonprotocol/ethers-sdk @bosonprotocol/ipfs-storage ethers
13
+
14
+ # OR
15
+
16
+ yarn add @bosonprotocol/core-sdk @bosonprotocol/ethers-sdk @bosonprotocol/ipfs-storage ethers
17
+ ```
18
+
19
+ We currently support the following
20
+
21
+ - `Web3LibAdapter` implementations:
22
+
23
+ - `EthersAdapter` exported from [`@bosonprotocol/ethers-sdk`](/packages/ethers-sdk/README.md)
24
+ - `EthConnectAdapter` exported from [`@bosonprotocol/eth-connect-sdk`](/packages/eth-connect-sdk/README.md)
25
+
26
+ - `MetadataStorage` implementations:
27
+ - `IpfsMetadata` exported from [`@bosonprotocol/ipfs-storage`](/packages/ipfs-storage/README.md)
28
+
29
+ ## Usage
30
+
31
+ > The following assumes the usage of the `core-sdk` with `ethers` and `IPFS` as the metadata storage.
32
+
33
+ - [Initialize sdk](#initialize)
34
+ - [Metadata](#metadata)
35
+ - [Offers](#offers)
36
+ - [Exchange token](#exchange-token)
37
+
38
+ ### Initialize
39
+
40
+ #### Explicit
41
+
42
+ The `core-sdk` can be initialized by explicitly passing in the required arguments
43
+
44
+ ```js
45
+ import { CoreSDK } from "@bosonprotocol/core-sdk";
46
+ import { EthersAdapter } from "@bosonprotocol/ethers-sdk";
47
+ import { IpfsMetadata } from "@bosonprotocol/ipfs-storage";
48
+ import { ethers } from "ethers";
49
+
50
+ // injected web3 provider
51
+ const web3Provider = new ethers.providers.Web3Provider(window.ethereum);
52
+
53
+ // initialize explicitly
54
+ const coreSDK = new CoreSDK({
55
+ web3Lib: new EthersAdapter(web3Provider),
56
+ subgraphUrl: "https://api.thegraph.com/subgraphs/name/bosonprotocol/cc",
57
+ protocolDiamond: "0x5E3f5127e320aD0C38a21970E327eefEf12561E5",
58
+ // optional
59
+ metadataStorage: new IpfsMetadata({
60
+ url: "https://ipfs.infura.io:5001"
61
+ }),
62
+ // optional
63
+ theGraphStorage: new IpfsMetadata({
64
+ url: "https://api.thegraph.com/ipfs/api/v0"
65
+ })
66
+ });
67
+ ```
68
+
69
+ #### Default configuration
70
+
71
+ It is also possible to use the default configuration provided through the [`@bosonprotocol/common`](/packages/common/README.md) package.
72
+
73
+ ```js
74
+ import { CoreSDK } from "@bosonprotocol/core-sdk";
75
+ import { EthersAdapter } from "@bosonprotocol/ethers-sdk";
76
+ import { IpfsMetadata } from "@bosonprotocol/ipfs-storage";
77
+ import { ethers } from "ethers";
78
+
79
+ // injected web3 provider
80
+ const web3Provider = new ethers.providers.Web3Provider(window.ethereum);
81
+
82
+ // initialize via default config of chainId = 3
83
+ const coreSDK = CoreSDK.fromDefaultConfig({
84
+ web3Lib: new EthersAdapter(web3Provider),
85
+ chainId: 3
86
+ // ...other args
87
+ });
88
+ ```
89
+
90
+ ### Metadata
91
+
92
+ For handling metadata through the `core-sdk`, make sure to pass an instance as a constructor argument
93
+
94
+ ```js
95
+ import { CoreSDK } from "@bosonprotocol/core-sdk";
96
+ import { IpfsMetadata } from "@bosonprotocol/ipfs-storage";
97
+
98
+ const ipfsMetadata = new IpfsMetadata({ url: "https://ipfs.infura.io:5001" });
99
+ const coreSDK = CoreSDK.fromDefaultConfig({
100
+ // ...other args
101
+ metadataStorage: ipfsMetadata
102
+ });
103
+
104
+ // store metadata
105
+ const cid = await coreSDK.storeMetadata(offerMetadata);
106
+
107
+ // get metadata
108
+ await coreSDK.getMetadata(cid);
109
+ ```
110
+
111
+ ### Offers
112
+
113
+ > TODO
114
+
115
+ ### Exchange token
116
+
117
+ > TODO
@@ -0,0 +1,48 @@
1
+ import { Web3LibAdapter, TransactionResponse, MetadataStorage, AnyMetadata, Log } from "@bosonprotocol/common";
2
+ import { BigNumberish } from "@ethersproject/bignumber";
3
+ import * as offers from "./offers";
4
+ import { MultiQueryOpts } from "./utils/subgraph";
5
+ export declare class CoreSDK {
6
+ private _web3Lib;
7
+ private _metadataStorage?;
8
+ private _theGraphStorage?;
9
+ private _subgraphUrl;
10
+ private _protocolDiamond;
11
+ constructor(opts: {
12
+ web3Lib: Web3LibAdapter;
13
+ subgraphUrl: string;
14
+ protocolDiamond: string;
15
+ metadataStorage?: MetadataStorage;
16
+ theGraphStorage?: MetadataStorage;
17
+ });
18
+ static fromDefaultConfig(args: {
19
+ web3Lib: Web3LibAdapter;
20
+ envName?: string;
21
+ chainId?: number;
22
+ metadataStorage?: MetadataStorage;
23
+ theGraphStorage?: MetadataStorage;
24
+ }): CoreSDK;
25
+ storeMetadata(metadata: AnyMetadata): Promise<string>;
26
+ getMetadata(metadataHashOrUri: string): Promise<AnyMetadata>;
27
+ createOffer(offerToCreate: offers.CreateOfferArgs, overrides?: Partial<{
28
+ contractAddress: string;
29
+ }>): Promise<TransactionResponse>;
30
+ getCreatedOfferIdFromLogs(logs: Log[]): string | null;
31
+ voidOffer(offerId: BigNumberish, overrides?: Partial<{
32
+ contractAddress: string;
33
+ }>): Promise<TransactionResponse>;
34
+ getOfferById(offerId: BigNumberish): Promise<offers.RawOfferFromSubgraph>;
35
+ getAllOffersOfSeller(sellerAddress: string, opts?: MultiQueryOpts): Promise<offers.RawOfferFromSubgraph[]>;
36
+ getExchangeTokenAllowance(exchangeToken: string, overrides?: Partial<{
37
+ spender: string;
38
+ owner: string;
39
+ }>): Promise<string>;
40
+ getExchangeTokenInfo(exchangeToken: string): Promise<{
41
+ name: string;
42
+ decimals: number;
43
+ symbol: string;
44
+ }>;
45
+ approveExchangeToken(exchangeToken: string, value: BigNumberish, overrides?: Partial<{
46
+ spender: string;
47
+ }>): Promise<TransactionResponse>;
48
+ }
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.CoreSDK = void 0;
36
+ const common_1 = require("@bosonprotocol/common");
37
+ const offers = __importStar(require("./offers"));
38
+ const erc20 = __importStar(require("./erc20"));
39
+ class CoreSDK {
40
+ constructor(opts) {
41
+ this._web3Lib = opts.web3Lib;
42
+ this._subgraphUrl = opts.subgraphUrl;
43
+ this._protocolDiamond = opts.protocolDiamond;
44
+ this._metadataStorage = opts.metadataStorage;
45
+ this._theGraphStorage = opts.theGraphStorage;
46
+ }
47
+ static fromDefaultConfig(args) {
48
+ const defaultConfig = (0, common_1.getDefaultConfig)({
49
+ envName: args.envName,
50
+ chainId: args.chainId
51
+ });
52
+ return new CoreSDK({
53
+ web3Lib: args.web3Lib,
54
+ metadataStorage: args.metadataStorage,
55
+ theGraphStorage: args.theGraphStorage,
56
+ subgraphUrl: defaultConfig.subgraphUrl,
57
+ protocolDiamond: defaultConfig.contracts.protocolDiamond
58
+ });
59
+ }
60
+ storeMetadata(metadata) {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ if (!this._metadataStorage) {
63
+ throw new Error("No metadata storage set");
64
+ }
65
+ return this._metadataStorage.storeMetadata(metadata);
66
+ });
67
+ }
68
+ getMetadata(metadataHashOrUri) {
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ if (!this._metadataStorage) {
71
+ throw new Error("No metadata storage set");
72
+ }
73
+ return this._metadataStorage.getMetadata(metadataHashOrUri);
74
+ });
75
+ }
76
+ createOffer(offerToCreate, overrides = {}) {
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ return offers.handler.createOffer({
79
+ offerToCreate,
80
+ web3Lib: this._web3Lib,
81
+ theGraphStorage: this._theGraphStorage,
82
+ metadataStorage: this._metadataStorage,
83
+ contractAddress: overrides.contractAddress || this._protocolDiamond
84
+ });
85
+ });
86
+ }
87
+ getCreatedOfferIdFromLogs(logs) {
88
+ return offers.iface.getCreatedOfferIdFromLogs(logs);
89
+ }
90
+ voidOffer(offerId, overrides = {}) {
91
+ return __awaiter(this, void 0, void 0, function* () {
92
+ return offers.handler.voidOffer({
93
+ offerId,
94
+ web3Lib: this._web3Lib,
95
+ subgraphUrl: this._subgraphUrl,
96
+ contractAddress: overrides.contractAddress || this._protocolDiamond
97
+ });
98
+ });
99
+ }
100
+ getOfferById(offerId) {
101
+ return __awaiter(this, void 0, void 0, function* () {
102
+ return offers.subgraph.getOfferById(this._subgraphUrl, offerId);
103
+ });
104
+ }
105
+ getAllOffersOfSeller(sellerAddress, opts = {}) {
106
+ return __awaiter(this, void 0, void 0, function* () {
107
+ return offers.subgraph.getAllOffersOfSeller(this._subgraphUrl, sellerAddress, opts);
108
+ });
109
+ }
110
+ getExchangeTokenAllowance(exchangeToken, overrides = {}) {
111
+ return __awaiter(this, void 0, void 0, function* () {
112
+ return erc20.handler.getAllowance({
113
+ web3Lib: this._web3Lib,
114
+ contractAddress: exchangeToken,
115
+ spender: overrides.spender || this._protocolDiamond,
116
+ owner: overrides.owner || (yield this._web3Lib.getSignerAddress())
117
+ });
118
+ });
119
+ }
120
+ getExchangeTokenInfo(exchangeToken) {
121
+ return __awaiter(this, void 0, void 0, function* () {
122
+ const args = {
123
+ web3Lib: this._web3Lib,
124
+ contractAddress: exchangeToken
125
+ };
126
+ const [decimals, name, symbol] = yield Promise.all([
127
+ erc20.handler.getDecimals(args),
128
+ erc20.handler.getName(args),
129
+ erc20.handler.getSymbol(args)
130
+ ]);
131
+ return { decimals, name, symbol };
132
+ });
133
+ }
134
+ approveExchangeToken(exchangeToken, value, overrides = {}) {
135
+ return __awaiter(this, void 0, void 0, function* () {
136
+ return erc20.handler.approve({
137
+ contractAddress: exchangeToken,
138
+ spender: overrides.spender || this._protocolDiamond,
139
+ value,
140
+ web3Lib: this._web3Lib
141
+ });
142
+ });
143
+ }
144
+ }
145
+ exports.CoreSDK = CoreSDK;
@@ -0,0 +1,26 @@
1
+ import { Web3LibAdapter } from "@bosonprotocol/common";
2
+ import { BigNumberish } from "@ethersproject/bignumber";
3
+ export declare function approve(args: {
4
+ contractAddress: string;
5
+ spender: string;
6
+ value: BigNumberish;
7
+ web3Lib: Web3LibAdapter;
8
+ }): Promise<import("@bosonprotocol/common").TransactionResponse>;
9
+ export declare function getAllowance(args: {
10
+ contractAddress: string;
11
+ owner: string;
12
+ spender: string;
13
+ web3Lib: Web3LibAdapter;
14
+ }): Promise<string>;
15
+ export declare function getDecimals(args: {
16
+ contractAddress: string;
17
+ web3Lib: Web3LibAdapter;
18
+ }): Promise<number>;
19
+ export declare function getSymbol(args: {
20
+ contractAddress: string;
21
+ web3Lib: Web3LibAdapter;
22
+ }): Promise<string>;
23
+ export declare function getName(args: {
24
+ contractAddress: string;
25
+ web3Lib: Web3LibAdapter;
26
+ }): Promise<string>;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getName = exports.getSymbol = exports.getDecimals = exports.getAllowance = exports.approve = void 0;
13
+ const interface_1 = require("./interface");
14
+ function approve(args) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ return args.web3Lib.sendTransaction({
17
+ to: args.contractAddress,
18
+ data: interface_1.erc20Iface.encodeFunctionData("approve", [args.spender, args.value])
19
+ });
20
+ });
21
+ }
22
+ exports.approve = approve;
23
+ function getAllowance(args) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ const result = yield args.web3Lib.call({
26
+ to: args.contractAddress,
27
+ data: interface_1.erc20Iface.encodeFunctionData("allowance", [args.owner, args.spender])
28
+ });
29
+ const [allowance] = interface_1.erc20Iface.decodeFunctionResult("allowance", result);
30
+ return String(allowance);
31
+ });
32
+ }
33
+ exports.getAllowance = getAllowance;
34
+ function getDecimals(args) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ const result = yield args.web3Lib.call({
37
+ to: args.contractAddress,
38
+ data: interface_1.erc20Iface.encodeFunctionData("decimals", [])
39
+ });
40
+ const [decimals] = interface_1.erc20Iface.decodeFunctionResult("decimals", result);
41
+ return Number(decimals);
42
+ });
43
+ }
44
+ exports.getDecimals = getDecimals;
45
+ function getSymbol(args) {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ const result = yield args.web3Lib.call({
48
+ to: args.contractAddress,
49
+ data: interface_1.erc20Iface.encodeFunctionData("symbol", [])
50
+ });
51
+ const [symbols] = interface_1.erc20Iface.decodeFunctionResult("symbol", result);
52
+ return String(symbols);
53
+ });
54
+ }
55
+ exports.getSymbol = getSymbol;
56
+ function getName(args) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ const result = yield args.web3Lib.call({
59
+ to: args.contractAddress,
60
+ data: interface_1.erc20Iface.encodeFunctionData("name", [])
61
+ });
62
+ const [name] = interface_1.erc20Iface.decodeFunctionResult("name", result);
63
+ return String(name);
64
+ });
65
+ }
66
+ exports.getName = getName;
@@ -0,0 +1,2 @@
1
+ export * as handler from "./handler";
2
+ export * as iface from "./interface";
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.iface = exports.handler = void 0;
27
+ exports.handler = __importStar(require("./handler"));
28
+ exports.iface = __importStar(require("./interface"));
@@ -0,0 +1,2 @@
1
+ import { Interface } from "@ethersproject/abi";
2
+ export declare const erc20Iface: Interface;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.erc20Iface = void 0;
4
+ const common_1 = require("@bosonprotocol/common");
5
+ const abi_1 = require("@ethersproject/abi");
6
+ exports.erc20Iface = new abi_1.Interface(common_1.abis.ERC20ABI);
@@ -0,0 +1,4 @@
1
+ export { CoreSDK } from "./core-sdk";
2
+ export * as offers from "./offers";
3
+ export * as erc20 from "./erc20";
4
+ export { defaultConfigs, getDefaultConfig, MetadataType, AnyMetadata } from "@bosonprotocol/common";