@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.
- package/LICENSE.md +192 -0
- package/README.md +117 -0
- package/dist/cjs/core-sdk.d.ts +48 -0
- package/dist/cjs/core-sdk.js +145 -0
- package/dist/cjs/erc20/handler.d.ts +26 -0
- package/dist/cjs/erc20/handler.js +66 -0
- package/dist/cjs/erc20/index.d.ts +2 -0
- package/dist/cjs/erc20/index.js +28 -0
- package/dist/cjs/erc20/interface.d.ts +2 -0
- package/dist/cjs/erc20/interface.js +6 -0
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.js +34 -0
- package/dist/cjs/offers/handler.d.ts +21 -0
- package/dist/cjs/offers/handler.js +66 -0
- package/dist/cjs/offers/index.d.ts +67 -0
- package/dist/cjs/offers/index.js +39 -0
- package/dist/cjs/offers/interface.d.ts +8 -0
- package/dist/cjs/offers/interface.js +42 -0
- package/dist/cjs/offers/subgraph.d.ts +8 -0
- package/dist/cjs/offers/subgraph.js +93 -0
- package/dist/cjs/offers/types.d.ts +33 -0
- package/dist/cjs/offers/types.js +2 -0
- package/dist/cjs/utils/errors.d.ts +9 -0
- package/dist/cjs/utils/errors.js +11 -0
- package/dist/cjs/utils/subgraph.d.ts +7 -0
- package/dist/cjs/utils/subgraph.js +45 -0
- package/dist/esm/core-sdk.d.ts +48 -0
- package/dist/esm/core-sdk.js +96 -0
- package/dist/esm/erc20/handler.d.ts +26 -0
- package/dist/esm/erc20/handler.js +39 -0
- package/dist/esm/erc20/index.d.ts +2 -0
- package/dist/esm/erc20/index.js +2 -0
- package/dist/esm/erc20/interface.d.ts +2 -0
- package/dist/esm/erc20/interface.js +3 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/offers/handler.d.ts +21 -0
- package/dist/esm/offers/handler.js +45 -0
- package/dist/esm/offers/index.d.ts +67 -0
- package/dist/esm/offers/index.js +10 -0
- package/dist/esm/offers/interface.d.ts +8 -0
- package/dist/esm/offers/interface.js +34 -0
- package/dist/esm/offers/subgraph.d.ts +8 -0
- package/dist/esm/offers/subgraph.js +82 -0
- package/dist/esm/offers/types.d.ts +33 -0
- package/dist/esm/offers/types.js +1 -0
- package/dist/esm/utils/errors.d.ts +9 -0
- package/dist/esm/utils/errors.js +9 -0
- package/dist/esm/utils/subgraph.d.ts +7 -0
- package/dist/esm/utils/subgraph.js +27 -0
- package/package.json +49 -0
|
@@ -0,0 +1,34 @@
|
|
|
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.MetadataType = exports.getDefaultConfig = exports.defaultConfigs = exports.erc20 = exports.offers = exports.CoreSDK = void 0;
|
|
27
|
+
var core_sdk_1 = require("./core-sdk");
|
|
28
|
+
Object.defineProperty(exports, "CoreSDK", { enumerable: true, get: function () { return core_sdk_1.CoreSDK; } });
|
|
29
|
+
exports.offers = __importStar(require("./offers"));
|
|
30
|
+
exports.erc20 = __importStar(require("./erc20"));
|
|
31
|
+
var common_1 = require("@bosonprotocol/common");
|
|
32
|
+
Object.defineProperty(exports, "defaultConfigs", { enumerable: true, get: function () { return common_1.defaultConfigs; } });
|
|
33
|
+
Object.defineProperty(exports, "getDefaultConfig", { enumerable: true, get: function () { return common_1.getDefaultConfig; } });
|
|
34
|
+
Object.defineProperty(exports, "MetadataType", { enumerable: true, get: function () { return common_1.MetadataType; } });
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BigNumberish } from "@ethersproject/bignumber";
|
|
2
|
+
import { Web3LibAdapter, TransactionResponse, MetadataStorage } from "@bosonprotocol/common";
|
|
3
|
+
import { CreateOfferArgs } from "./types";
|
|
4
|
+
export declare function createOffer(args: {
|
|
5
|
+
offerToCreate: CreateOfferArgs;
|
|
6
|
+
contractAddress: string;
|
|
7
|
+
web3Lib: Web3LibAdapter;
|
|
8
|
+
metadataStorage?: MetadataStorage;
|
|
9
|
+
theGraphStorage?: MetadataStorage;
|
|
10
|
+
}): Promise<TransactionResponse>;
|
|
11
|
+
export declare function voidOffer(args: {
|
|
12
|
+
contractAddress: string;
|
|
13
|
+
subgraphUrl: string;
|
|
14
|
+
offerId: BigNumberish;
|
|
15
|
+
web3Lib: Web3LibAdapter;
|
|
16
|
+
}): Promise<TransactionResponse>;
|
|
17
|
+
export declare function storeMetadataOnTheGraph(args: {
|
|
18
|
+
metadataUriOrHash: string;
|
|
19
|
+
metadataStorage: MetadataStorage;
|
|
20
|
+
theGraphStorage: MetadataStorage;
|
|
21
|
+
}): 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.storeMetadataOnTheGraph = exports.voidOffer = exports.createOffer = void 0;
|
|
13
|
+
const common_1 = require("@bosonprotocol/common");
|
|
14
|
+
const interface_1 = require("./interface");
|
|
15
|
+
const subgraph_1 = require("./subgraph");
|
|
16
|
+
function createOffer(args) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
yield common_1.utils.validation.createOfferArgsSchema.validate(args.offerToCreate, {
|
|
19
|
+
abortEarly: false
|
|
20
|
+
});
|
|
21
|
+
// We use the feature `ipfsOnEthereum` in our subgraph to resolve metadata from IPFS
|
|
22
|
+
// and store them in the graph. In order for the graph node to reliably resolve them,
|
|
23
|
+
// we need to add the metadata additionally to the IPFS node of the graph.
|
|
24
|
+
// See https://thegraph.com/docs/en/developer/assemblyscript-api/#ipfs-api
|
|
25
|
+
if (args.metadataStorage && args.theGraphStorage) {
|
|
26
|
+
yield storeMetadataOnTheGraph({
|
|
27
|
+
metadataUriOrHash: args.offerToCreate.metadataHash,
|
|
28
|
+
metadataStorage: args.metadataStorage,
|
|
29
|
+
theGraphStorage: args.theGraphStorage
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return args.web3Lib.sendTransaction({
|
|
33
|
+
to: args.contractAddress,
|
|
34
|
+
data: (0, interface_1.encodeCreateOffer)(args.offerToCreate)
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
exports.createOffer = createOffer;
|
|
39
|
+
function voidOffer(args) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
const offer = yield (0, subgraph_1.getOfferById)(args.subgraphUrl, args.offerId);
|
|
42
|
+
if (!offer) {
|
|
43
|
+
throw new Error(`Offer with id "${args.offerId}" does not exist`);
|
|
44
|
+
}
|
|
45
|
+
if (offer.voidedAt) {
|
|
46
|
+
throw new Error(`Offer with id "${args.offerId}" is already voided`);
|
|
47
|
+
}
|
|
48
|
+
const signerAddress = yield args.web3Lib.getSignerAddress();
|
|
49
|
+
if (offer.seller.address.toLowerCase() !== signerAddress.toLowerCase()) {
|
|
50
|
+
throw new Error(`Signer with address "${signerAddress}" is not the seller "${offer.seller.address}"`);
|
|
51
|
+
}
|
|
52
|
+
return args.web3Lib.sendTransaction({
|
|
53
|
+
to: args.contractAddress,
|
|
54
|
+
data: interface_1.bosonOfferHandlerIface.encodeFunctionData("voidOffer", [args.offerId])
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
exports.voidOffer = voidOffer;
|
|
59
|
+
function storeMetadataOnTheGraph(args) {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
const metadata = yield args.metadataStorage.getMetadata(args.metadataUriOrHash);
|
|
62
|
+
const metadataUri = yield args.theGraphStorage.storeMetadata(metadata);
|
|
63
|
+
return metadataUri;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
exports.storeMetadataOnTheGraph = storeMetadataOnTheGraph;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export * as handler from "./handler";
|
|
2
|
+
export * as subgraph from "./subgraph";
|
|
3
|
+
export * as iface from "./interface";
|
|
4
|
+
export * from "./types";
|
|
5
|
+
export declare const validation: {
|
|
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>;
|
|
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>;
|
|
34
|
+
}>>;
|
|
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>;
|
|
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>;
|
|
47
|
+
}>>;
|
|
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>;
|
|
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>;
|
|
66
|
+
}>>;
|
|
67
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.validation = exports.iface = exports.subgraph = exports.handler = void 0;
|
|
30
|
+
const common_1 = require("@bosonprotocol/common");
|
|
31
|
+
exports.handler = __importStar(require("./handler"));
|
|
32
|
+
exports.subgraph = __importStar(require("./subgraph"));
|
|
33
|
+
exports.iface = __importStar(require("./interface"));
|
|
34
|
+
__exportStar(require("./types"), exports);
|
|
35
|
+
exports.validation = {
|
|
36
|
+
createOfferArgsSchema: common_1.utils.validation.createOfferArgsSchema,
|
|
37
|
+
baseMetadataSchema: common_1.utils.validation.baseMetadataSchema,
|
|
38
|
+
productV1MetadataSchema: common_1.utils.validation.productV1MetadataSchema
|
|
39
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { OfferStruct, Log } from "@bosonprotocol/common";
|
|
2
|
+
import { Interface } from "@ethersproject/abi";
|
|
3
|
+
import { CreateOfferArgs } from "./types";
|
|
4
|
+
export declare const bosonOfferHandlerIface: Interface;
|
|
5
|
+
export declare function getCreatedOfferIdFromLogs(logs: Log[]): string | null;
|
|
6
|
+
export declare function parseLog(data: string, topics: string[]): import("@ethersproject/abi").LogDescription;
|
|
7
|
+
export declare function encodeCreateOffer(args: CreateOfferArgs): string;
|
|
8
|
+
export declare function createOfferArgsToStruct(args: CreateOfferArgs): Partial<OfferStruct>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.createOfferArgsToStruct = exports.encodeCreateOffer = exports.parseLog = exports.getCreatedOfferIdFromLogs = exports.bosonOfferHandlerIface = void 0;
|
|
15
|
+
const common_1 = require("@bosonprotocol/common");
|
|
16
|
+
const abi_1 = require("@ethersproject/abi");
|
|
17
|
+
const address_1 = require("@ethersproject/address");
|
|
18
|
+
exports.bosonOfferHandlerIface = new abi_1.Interface(common_1.abis.IBosonOfferHandlerABI);
|
|
19
|
+
function getCreatedOfferIdFromLogs(logs) {
|
|
20
|
+
const parsedLogs = logs.map((log) => parseLog(log.data, log.topics));
|
|
21
|
+
const [offerCreatedLog] = parsedLogs.filter((log) => log.name === "OfferCreated");
|
|
22
|
+
if (!offerCreatedLog) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
return String(offerCreatedLog.args.offerId);
|
|
26
|
+
}
|
|
27
|
+
exports.getCreatedOfferIdFromLogs = getCreatedOfferIdFromLogs;
|
|
28
|
+
function parseLog(data, topics) {
|
|
29
|
+
return exports.bosonOfferHandlerIface.parseLog({ data, topics });
|
|
30
|
+
}
|
|
31
|
+
exports.parseLog = parseLog;
|
|
32
|
+
function encodeCreateOffer(args) {
|
|
33
|
+
return exports.bosonOfferHandlerIface.encodeFunctionData("createOffer", [
|
|
34
|
+
createOfferArgsToStruct(args)
|
|
35
|
+
]);
|
|
36
|
+
}
|
|
37
|
+
exports.encodeCreateOffer = encodeCreateOffer;
|
|
38
|
+
function createOfferArgsToStruct(args) {
|
|
39
|
+
const { exchangeToken, seller, validFromDateInMS, validUntilDateInMS, redeemableDateInMS, fulfillmentPeriodDurationInMS, voucherValidDurationInMS } = args, restArgs = __rest(args, ["exchangeToken", "seller", "validFromDateInMS", "validUntilDateInMS", "redeemableDateInMS", "fulfillmentPeriodDurationInMS", "voucherValidDurationInMS"]);
|
|
40
|
+
return Object.assign(Object.assign({ id: "0" }, restArgs), { exchangeToken: (0, address_1.getAddress)(exchangeToken), seller: (0, address_1.getAddress)(seller), validFromDate: common_1.utils.timestamp.msToSec(validFromDateInMS), validUntilDate: common_1.utils.timestamp.msToSec(validUntilDateInMS), redeemableDate: common_1.utils.timestamp.msToSec(redeemableDateInMS), fulfillmentPeriodDuration: common_1.utils.timestamp.msToSec(fulfillmentPeriodDurationInMS), voucherValidDuration: common_1.utils.timestamp.msToSec(voucherValidDurationInMS) });
|
|
41
|
+
}
|
|
42
|
+
exports.createOfferArgsToStruct = createOfferArgsToStruct;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BigNumberish } from "@ethersproject/bignumber";
|
|
2
|
+
import { MultiQueryOpts } from "../utils/subgraph";
|
|
3
|
+
import { RawOfferFromSubgraph } from "./types";
|
|
4
|
+
export declare const offerFieldsFragment = "\nfragment offerFields on Offer {\n id\n createdAt\n price\n deposit\n penalty\n quantity\n validFromDate\n validUntilDate\n redeemableDate\n fulfillmentPeriodDuration\n voucherValidDuration\n metadataUri\n metadataHash\n voidedAt\n seller {\n address\n }\n exchangeToken {\n address\n decimals\n name\n symbol\n }\n metadata {\n name \n description\n externalUrl\n schemaUrl\n type\n }\n}\n";
|
|
5
|
+
export declare const getOfferByIdQuery: string;
|
|
6
|
+
export declare function getOfferById(subgraphUrl: string, offerId: BigNumberish): Promise<RawOfferFromSubgraph>;
|
|
7
|
+
export declare const getAllOffersOfSellerQuery: string;
|
|
8
|
+
export declare function getAllOffersOfSeller(subgraphUrl: string, sellerAddress: string, opts?: MultiQueryOpts): Promise<RawOfferFromSubgraph[]>;
|
|
@@ -0,0 +1,93 @@
|
|
|
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.getAllOffersOfSeller = exports.getAllOffersOfSellerQuery = exports.getOfferById = exports.getOfferByIdQuery = exports.offerFieldsFragment = void 0;
|
|
13
|
+
const subgraph_1 = require("../utils/subgraph");
|
|
14
|
+
exports.offerFieldsFragment = `
|
|
15
|
+
fragment offerFields on Offer {
|
|
16
|
+
id
|
|
17
|
+
createdAt
|
|
18
|
+
price
|
|
19
|
+
deposit
|
|
20
|
+
penalty
|
|
21
|
+
quantity
|
|
22
|
+
validFromDate
|
|
23
|
+
validUntilDate
|
|
24
|
+
redeemableDate
|
|
25
|
+
fulfillmentPeriodDuration
|
|
26
|
+
voucherValidDuration
|
|
27
|
+
metadataUri
|
|
28
|
+
metadataHash
|
|
29
|
+
voidedAt
|
|
30
|
+
seller {
|
|
31
|
+
address
|
|
32
|
+
}
|
|
33
|
+
exchangeToken {
|
|
34
|
+
address
|
|
35
|
+
decimals
|
|
36
|
+
name
|
|
37
|
+
symbol
|
|
38
|
+
}
|
|
39
|
+
metadata {
|
|
40
|
+
name
|
|
41
|
+
description
|
|
42
|
+
externalUrl
|
|
43
|
+
schemaUrl
|
|
44
|
+
type
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
48
|
+
exports.getOfferByIdQuery = `
|
|
49
|
+
query GetOfferById($offerId: ID!) {
|
|
50
|
+
offer(id: $offerId) {
|
|
51
|
+
...offerFields
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
${exports.offerFieldsFragment}
|
|
55
|
+
`;
|
|
56
|
+
function getOfferById(subgraphUrl, offerId) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
const { offer } = yield (0, subgraph_1.fetchSubgraph)(subgraphUrl, exports.getOfferByIdQuery, { offerId: offerId.toString() });
|
|
59
|
+
return offer;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
exports.getOfferById = getOfferById;
|
|
63
|
+
exports.getAllOffersOfSellerQuery = `
|
|
64
|
+
query GetAllOffersOfSellerQuery(
|
|
65
|
+
$seller: ID!,
|
|
66
|
+
$first: Int,
|
|
67
|
+
$skip: Int,
|
|
68
|
+
$orderBy: String,
|
|
69
|
+
$orderDirection: String
|
|
70
|
+
) {
|
|
71
|
+
seller(id: $seller) {
|
|
72
|
+
offers(
|
|
73
|
+
first: $first
|
|
74
|
+
skip: $skip
|
|
75
|
+
orderBy: $orderBy
|
|
76
|
+
orderDirection: $orderDirection
|
|
77
|
+
) {
|
|
78
|
+
...offerFields
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
${exports.offerFieldsFragment}
|
|
83
|
+
`;
|
|
84
|
+
function getAllOffersOfSeller(subgraphUrl, sellerAddress, opts = {}) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
const { seller } = yield (0, subgraph_1.fetchSubgraph)(subgraphUrl, exports.getAllOffersOfSellerQuery, Object.assign({ seller: sellerAddress.toLowerCase(), first: 100, skip: 0, orderBy: "createdAt", orderDirection: "desc" }, opts));
|
|
87
|
+
if (!seller) {
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
return seller.offers;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
exports.getAllOffersOfSeller = getAllOffersOfSeller;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export { CreateOfferArgs } from "@bosonprotocol/common";
|
|
2
|
+
export declare type RawOfferFromSubgraph = {
|
|
3
|
+
id: string;
|
|
4
|
+
createdAt: string;
|
|
5
|
+
price: string;
|
|
6
|
+
deposit: string;
|
|
7
|
+
penalty: string;
|
|
8
|
+
quantity: string;
|
|
9
|
+
validFromDate: string;
|
|
10
|
+
validUntilDate: string;
|
|
11
|
+
redeemableDate: string;
|
|
12
|
+
fulfillmentPeriodDuration: string;
|
|
13
|
+
voucherValidDuration: string;
|
|
14
|
+
metadataUri: string;
|
|
15
|
+
metadataHash: string;
|
|
16
|
+
voidedAt: null | string;
|
|
17
|
+
seller: {
|
|
18
|
+
address: string;
|
|
19
|
+
};
|
|
20
|
+
exchangeToken: {
|
|
21
|
+
address: string;
|
|
22
|
+
decimals: string;
|
|
23
|
+
name: string;
|
|
24
|
+
symbol: string;
|
|
25
|
+
};
|
|
26
|
+
metadata: null | {
|
|
27
|
+
name: string;
|
|
28
|
+
description: string;
|
|
29
|
+
externalUrl: string;
|
|
30
|
+
schemaUrl: string;
|
|
31
|
+
type: string;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FetchError = void 0;
|
|
4
|
+
class FetchError extends Error {
|
|
5
|
+
constructor(args) {
|
|
6
|
+
super(args.message);
|
|
7
|
+
this.statusCode = args.statusCode;
|
|
8
|
+
this.statusText = args.statusText;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.FetchError = FetchError;
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.fetchSubgraph = void 0;
|
|
16
|
+
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
|
17
|
+
const errors_1 = require("./errors");
|
|
18
|
+
function fetchSubgraph(subgraphUrl, query, variables) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
const response = yield (0, cross_fetch_1.default)(subgraphUrl, {
|
|
21
|
+
method: "POST",
|
|
22
|
+
headers: {
|
|
23
|
+
"Content-Type": "application/json"
|
|
24
|
+
},
|
|
25
|
+
body: JSON.stringify({
|
|
26
|
+
query,
|
|
27
|
+
variables
|
|
28
|
+
})
|
|
29
|
+
});
|
|
30
|
+
if (!response.ok) {
|
|
31
|
+
throw new errors_1.FetchError({
|
|
32
|
+
message: `Failed to fetch: ${response.status} ${response.statusText}`,
|
|
33
|
+
statusCode: response.status,
|
|
34
|
+
statusText: response.statusText
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const body = yield response.json();
|
|
38
|
+
const { data = {}, errors = [] } = body || {};
|
|
39
|
+
if (errors.length > 0) {
|
|
40
|
+
throw new Error(`GraphQL errors: ${JSON.stringify(errors)}`);
|
|
41
|
+
}
|
|
42
|
+
return data;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
exports.fetchSubgraph = fetchSubgraph;
|
|
@@ -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,96 @@
|
|
|
1
|
+
import { getDefaultConfig } from "@bosonprotocol/common";
|
|
2
|
+
import * as offers from "./offers";
|
|
3
|
+
import * as erc20 from "./erc20";
|
|
4
|
+
export class CoreSDK {
|
|
5
|
+
_web3Lib;
|
|
6
|
+
_metadataStorage;
|
|
7
|
+
_theGraphStorage;
|
|
8
|
+
_subgraphUrl;
|
|
9
|
+
_protocolDiamond;
|
|
10
|
+
constructor(opts) {
|
|
11
|
+
this._web3Lib = opts.web3Lib;
|
|
12
|
+
this._subgraphUrl = opts.subgraphUrl;
|
|
13
|
+
this._protocolDiamond = opts.protocolDiamond;
|
|
14
|
+
this._metadataStorage = opts.metadataStorage;
|
|
15
|
+
this._theGraphStorage = opts.theGraphStorage;
|
|
16
|
+
}
|
|
17
|
+
static fromDefaultConfig(args) {
|
|
18
|
+
const defaultConfig = getDefaultConfig({
|
|
19
|
+
envName: args.envName,
|
|
20
|
+
chainId: args.chainId
|
|
21
|
+
});
|
|
22
|
+
return new CoreSDK({
|
|
23
|
+
web3Lib: args.web3Lib,
|
|
24
|
+
metadataStorage: args.metadataStorage,
|
|
25
|
+
theGraphStorage: args.theGraphStorage,
|
|
26
|
+
subgraphUrl: defaultConfig.subgraphUrl,
|
|
27
|
+
protocolDiamond: defaultConfig.contracts.protocolDiamond
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async storeMetadata(metadata) {
|
|
31
|
+
if (!this._metadataStorage) {
|
|
32
|
+
throw new Error("No metadata storage set");
|
|
33
|
+
}
|
|
34
|
+
return this._metadataStorage.storeMetadata(metadata);
|
|
35
|
+
}
|
|
36
|
+
async getMetadata(metadataHashOrUri) {
|
|
37
|
+
if (!this._metadataStorage) {
|
|
38
|
+
throw new Error("No metadata storage set");
|
|
39
|
+
}
|
|
40
|
+
return this._metadataStorage.getMetadata(metadataHashOrUri);
|
|
41
|
+
}
|
|
42
|
+
async createOffer(offerToCreate, overrides = {}) {
|
|
43
|
+
return offers.handler.createOffer({
|
|
44
|
+
offerToCreate,
|
|
45
|
+
web3Lib: this._web3Lib,
|
|
46
|
+
theGraphStorage: this._theGraphStorage,
|
|
47
|
+
metadataStorage: this._metadataStorage,
|
|
48
|
+
contractAddress: overrides.contractAddress || this._protocolDiamond
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
getCreatedOfferIdFromLogs(logs) {
|
|
52
|
+
return offers.iface.getCreatedOfferIdFromLogs(logs);
|
|
53
|
+
}
|
|
54
|
+
async voidOffer(offerId, overrides = {}) {
|
|
55
|
+
return offers.handler.voidOffer({
|
|
56
|
+
offerId,
|
|
57
|
+
web3Lib: this._web3Lib,
|
|
58
|
+
subgraphUrl: this._subgraphUrl,
|
|
59
|
+
contractAddress: overrides.contractAddress || this._protocolDiamond
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
async getOfferById(offerId) {
|
|
63
|
+
return offers.subgraph.getOfferById(this._subgraphUrl, offerId);
|
|
64
|
+
}
|
|
65
|
+
async getAllOffersOfSeller(sellerAddress, opts = {}) {
|
|
66
|
+
return offers.subgraph.getAllOffersOfSeller(this._subgraphUrl, sellerAddress, opts);
|
|
67
|
+
}
|
|
68
|
+
async getExchangeTokenAllowance(exchangeToken, overrides = {}) {
|
|
69
|
+
return erc20.handler.getAllowance({
|
|
70
|
+
web3Lib: this._web3Lib,
|
|
71
|
+
contractAddress: exchangeToken,
|
|
72
|
+
spender: overrides.spender || this._protocolDiamond,
|
|
73
|
+
owner: overrides.owner || (await this._web3Lib.getSignerAddress())
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
async getExchangeTokenInfo(exchangeToken) {
|
|
77
|
+
const args = {
|
|
78
|
+
web3Lib: this._web3Lib,
|
|
79
|
+
contractAddress: exchangeToken
|
|
80
|
+
};
|
|
81
|
+
const [decimals, name, symbol] = await Promise.all([
|
|
82
|
+
erc20.handler.getDecimals(args),
|
|
83
|
+
erc20.handler.getName(args),
|
|
84
|
+
erc20.handler.getSymbol(args)
|
|
85
|
+
]);
|
|
86
|
+
return { decimals, name, symbol };
|
|
87
|
+
}
|
|
88
|
+
async approveExchangeToken(exchangeToken, value, overrides = {}) {
|
|
89
|
+
return erc20.handler.approve({
|
|
90
|
+
contractAddress: exchangeToken,
|
|
91
|
+
spender: overrides.spender || this._protocolDiamond,
|
|
92
|
+
value,
|
|
93
|
+
web3Lib: this._web3Lib
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|