@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,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,39 @@
|
|
|
1
|
+
import { erc20Iface } from "./interface";
|
|
2
|
+
export async function approve(args) {
|
|
3
|
+
return args.web3Lib.sendTransaction({
|
|
4
|
+
to: args.contractAddress,
|
|
5
|
+
data: erc20Iface.encodeFunctionData("approve", [args.spender, args.value])
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
export async function getAllowance(args) {
|
|
9
|
+
const result = await args.web3Lib.call({
|
|
10
|
+
to: args.contractAddress,
|
|
11
|
+
data: erc20Iface.encodeFunctionData("allowance", [args.owner, args.spender])
|
|
12
|
+
});
|
|
13
|
+
const [allowance] = erc20Iface.decodeFunctionResult("allowance", result);
|
|
14
|
+
return String(allowance);
|
|
15
|
+
}
|
|
16
|
+
export async function getDecimals(args) {
|
|
17
|
+
const result = await args.web3Lib.call({
|
|
18
|
+
to: args.contractAddress,
|
|
19
|
+
data: erc20Iface.encodeFunctionData("decimals", [])
|
|
20
|
+
});
|
|
21
|
+
const [decimals] = erc20Iface.decodeFunctionResult("decimals", result);
|
|
22
|
+
return Number(decimals);
|
|
23
|
+
}
|
|
24
|
+
export async function getSymbol(args) {
|
|
25
|
+
const result = await args.web3Lib.call({
|
|
26
|
+
to: args.contractAddress,
|
|
27
|
+
data: erc20Iface.encodeFunctionData("symbol", [])
|
|
28
|
+
});
|
|
29
|
+
const [symbols] = erc20Iface.decodeFunctionResult("symbol", result);
|
|
30
|
+
return String(symbols);
|
|
31
|
+
}
|
|
32
|
+
export async function getName(args) {
|
|
33
|
+
const result = await args.web3Lib.call({
|
|
34
|
+
to: args.contractAddress,
|
|
35
|
+
data: erc20Iface.encodeFunctionData("name", [])
|
|
36
|
+
});
|
|
37
|
+
const [name] = erc20Iface.decodeFunctionResult("name", result);
|
|
38
|
+
return String(name);
|
|
39
|
+
}
|
|
@@ -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,45 @@
|
|
|
1
|
+
import { utils } from "@bosonprotocol/common";
|
|
2
|
+
import { bosonOfferHandlerIface, encodeCreateOffer } from "./interface";
|
|
3
|
+
import { getOfferById } from "./subgraph";
|
|
4
|
+
export async function createOffer(args) {
|
|
5
|
+
await utils.validation.createOfferArgsSchema.validate(args.offerToCreate, {
|
|
6
|
+
abortEarly: false
|
|
7
|
+
});
|
|
8
|
+
// We use the feature `ipfsOnEthereum` in our subgraph to resolve metadata from IPFS
|
|
9
|
+
// and store them in the graph. In order for the graph node to reliably resolve them,
|
|
10
|
+
// we need to add the metadata additionally to the IPFS node of the graph.
|
|
11
|
+
// See https://thegraph.com/docs/en/developer/assemblyscript-api/#ipfs-api
|
|
12
|
+
if (args.metadataStorage && args.theGraphStorage) {
|
|
13
|
+
await storeMetadataOnTheGraph({
|
|
14
|
+
metadataUriOrHash: args.offerToCreate.metadataHash,
|
|
15
|
+
metadataStorage: args.metadataStorage,
|
|
16
|
+
theGraphStorage: args.theGraphStorage
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return args.web3Lib.sendTransaction({
|
|
20
|
+
to: args.contractAddress,
|
|
21
|
+
data: encodeCreateOffer(args.offerToCreate)
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export async function voidOffer(args) {
|
|
25
|
+
const offer = await getOfferById(args.subgraphUrl, args.offerId);
|
|
26
|
+
if (!offer) {
|
|
27
|
+
throw new Error(`Offer with id "${args.offerId}" does not exist`);
|
|
28
|
+
}
|
|
29
|
+
if (offer.voidedAt) {
|
|
30
|
+
throw new Error(`Offer with id "${args.offerId}" is already voided`);
|
|
31
|
+
}
|
|
32
|
+
const signerAddress = await args.web3Lib.getSignerAddress();
|
|
33
|
+
if (offer.seller.address.toLowerCase() !== signerAddress.toLowerCase()) {
|
|
34
|
+
throw new Error(`Signer with address "${signerAddress}" is not the seller "${offer.seller.address}"`);
|
|
35
|
+
}
|
|
36
|
+
return args.web3Lib.sendTransaction({
|
|
37
|
+
to: args.contractAddress,
|
|
38
|
+
data: bosonOfferHandlerIface.encodeFunctionData("voidOffer", [args.offerId])
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
export async function storeMetadataOnTheGraph(args) {
|
|
42
|
+
const metadata = await args.metadataStorage.getMetadata(args.metadataUriOrHash);
|
|
43
|
+
const metadataUri = await args.theGraphStorage.storeMetadata(metadata);
|
|
44
|
+
return metadataUri;
|
|
45
|
+
}
|
|
@@ -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,10 @@
|
|
|
1
|
+
import { utils } from "@bosonprotocol/common";
|
|
2
|
+
export * as handler from "./handler";
|
|
3
|
+
export * as subgraph from "./subgraph";
|
|
4
|
+
export * as iface from "./interface";
|
|
5
|
+
export * from "./types";
|
|
6
|
+
export const validation = {
|
|
7
|
+
createOfferArgsSchema: utils.validation.createOfferArgsSchema,
|
|
8
|
+
baseMetadataSchema: utils.validation.baseMetadataSchema,
|
|
9
|
+
productV1MetadataSchema: utils.validation.productV1MetadataSchema
|
|
10
|
+
};
|
|
@@ -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,34 @@
|
|
|
1
|
+
import { utils, abis } from "@bosonprotocol/common";
|
|
2
|
+
import { Interface } from "@ethersproject/abi";
|
|
3
|
+
import { getAddress } from "@ethersproject/address";
|
|
4
|
+
export const bosonOfferHandlerIface = new Interface(abis.IBosonOfferHandlerABI);
|
|
5
|
+
export function getCreatedOfferIdFromLogs(logs) {
|
|
6
|
+
const parsedLogs = logs.map((log) => parseLog(log.data, log.topics));
|
|
7
|
+
const [offerCreatedLog] = parsedLogs.filter((log) => log.name === "OfferCreated");
|
|
8
|
+
if (!offerCreatedLog) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
return String(offerCreatedLog.args.offerId);
|
|
12
|
+
}
|
|
13
|
+
export function parseLog(data, topics) {
|
|
14
|
+
return bosonOfferHandlerIface.parseLog({ data, topics });
|
|
15
|
+
}
|
|
16
|
+
export function encodeCreateOffer(args) {
|
|
17
|
+
return bosonOfferHandlerIface.encodeFunctionData("createOffer", [
|
|
18
|
+
createOfferArgsToStruct(args)
|
|
19
|
+
]);
|
|
20
|
+
}
|
|
21
|
+
export function createOfferArgsToStruct(args) {
|
|
22
|
+
const { exchangeToken, seller, validFromDateInMS, validUntilDateInMS, redeemableDateInMS, fulfillmentPeriodDurationInMS, voucherValidDurationInMS, ...restArgs } = args;
|
|
23
|
+
return {
|
|
24
|
+
id: "0",
|
|
25
|
+
...restArgs,
|
|
26
|
+
exchangeToken: getAddress(exchangeToken),
|
|
27
|
+
seller: getAddress(seller),
|
|
28
|
+
validFromDate: utils.timestamp.msToSec(validFromDateInMS),
|
|
29
|
+
validUntilDate: utils.timestamp.msToSec(validUntilDateInMS),
|
|
30
|
+
redeemableDate: utils.timestamp.msToSec(redeemableDateInMS),
|
|
31
|
+
fulfillmentPeriodDuration: utils.timestamp.msToSec(fulfillmentPeriodDurationInMS),
|
|
32
|
+
voucherValidDuration: utils.timestamp.msToSec(voucherValidDurationInMS)
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -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,82 @@
|
|
|
1
|
+
import { fetchSubgraph } from "../utils/subgraph";
|
|
2
|
+
export const offerFieldsFragment = `
|
|
3
|
+
fragment offerFields on Offer {
|
|
4
|
+
id
|
|
5
|
+
createdAt
|
|
6
|
+
price
|
|
7
|
+
deposit
|
|
8
|
+
penalty
|
|
9
|
+
quantity
|
|
10
|
+
validFromDate
|
|
11
|
+
validUntilDate
|
|
12
|
+
redeemableDate
|
|
13
|
+
fulfillmentPeriodDuration
|
|
14
|
+
voucherValidDuration
|
|
15
|
+
metadataUri
|
|
16
|
+
metadataHash
|
|
17
|
+
voidedAt
|
|
18
|
+
seller {
|
|
19
|
+
address
|
|
20
|
+
}
|
|
21
|
+
exchangeToken {
|
|
22
|
+
address
|
|
23
|
+
decimals
|
|
24
|
+
name
|
|
25
|
+
symbol
|
|
26
|
+
}
|
|
27
|
+
metadata {
|
|
28
|
+
name
|
|
29
|
+
description
|
|
30
|
+
externalUrl
|
|
31
|
+
schemaUrl
|
|
32
|
+
type
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
`;
|
|
36
|
+
export const getOfferByIdQuery = `
|
|
37
|
+
query GetOfferById($offerId: ID!) {
|
|
38
|
+
offer(id: $offerId) {
|
|
39
|
+
...offerFields
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
${offerFieldsFragment}
|
|
43
|
+
`;
|
|
44
|
+
export async function getOfferById(subgraphUrl, offerId) {
|
|
45
|
+
const { offer } = await fetchSubgraph(subgraphUrl, getOfferByIdQuery, { offerId: offerId.toString() });
|
|
46
|
+
return offer;
|
|
47
|
+
}
|
|
48
|
+
export const getAllOffersOfSellerQuery = `
|
|
49
|
+
query GetAllOffersOfSellerQuery(
|
|
50
|
+
$seller: ID!,
|
|
51
|
+
$first: Int,
|
|
52
|
+
$skip: Int,
|
|
53
|
+
$orderBy: String,
|
|
54
|
+
$orderDirection: String
|
|
55
|
+
) {
|
|
56
|
+
seller(id: $seller) {
|
|
57
|
+
offers(
|
|
58
|
+
first: $first
|
|
59
|
+
skip: $skip
|
|
60
|
+
orderBy: $orderBy
|
|
61
|
+
orderDirection: $orderDirection
|
|
62
|
+
) {
|
|
63
|
+
...offerFields
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
${offerFieldsFragment}
|
|
68
|
+
`;
|
|
69
|
+
export async function getAllOffersOfSeller(subgraphUrl, sellerAddress, opts = {}) {
|
|
70
|
+
const { seller } = await fetchSubgraph(subgraphUrl, getAllOffersOfSellerQuery, {
|
|
71
|
+
seller: sellerAddress.toLowerCase(),
|
|
72
|
+
first: 100,
|
|
73
|
+
skip: 0,
|
|
74
|
+
orderBy: "createdAt",
|
|
75
|
+
orderDirection: "desc",
|
|
76
|
+
...opts
|
|
77
|
+
});
|
|
78
|
+
if (!seller) {
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
return seller.offers;
|
|
82
|
+
}
|
|
@@ -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 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import fetch from "cross-fetch";
|
|
2
|
+
import { FetchError } from "./errors";
|
|
3
|
+
export async function fetchSubgraph(subgraphUrl, query, variables) {
|
|
4
|
+
const response = await fetch(subgraphUrl, {
|
|
5
|
+
method: "POST",
|
|
6
|
+
headers: {
|
|
7
|
+
"Content-Type": "application/json"
|
|
8
|
+
},
|
|
9
|
+
body: JSON.stringify({
|
|
10
|
+
query,
|
|
11
|
+
variables
|
|
12
|
+
})
|
|
13
|
+
});
|
|
14
|
+
if (!response.ok) {
|
|
15
|
+
throw new FetchError({
|
|
16
|
+
message: `Failed to fetch: ${response.status} ${response.statusText}`,
|
|
17
|
+
statusCode: response.status,
|
|
18
|
+
statusText: response.statusText
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
const body = await response.json();
|
|
22
|
+
const { data = {}, errors = [] } = body || {};
|
|
23
|
+
if (errors.length > 0) {
|
|
24
|
+
throw new Error(`GraphQL errors: ${JSON.stringify(errors)}`);
|
|
25
|
+
}
|
|
26
|
+
return data;
|
|
27
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bosonprotocol/core-sdk",
|
|
3
|
+
"version": "1.1.0-alpha.0",
|
|
4
|
+
"description": "> TODO: description",
|
|
5
|
+
"main": "./dist/cjs/index.js",
|
|
6
|
+
"module": "./dist/esm/index.js",
|
|
7
|
+
"types": "./dist/cjs/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"dev": "tsc --build tsconfig.cjs.json --watch --preserveWatchOutput ",
|
|
10
|
+
"lint": "eslint --ignore-path ../../.gitignore --ext .js,.ts .",
|
|
11
|
+
"build": "rimraf dist && tsc && tsc --build tsconfig.cjs.json",
|
|
12
|
+
"test": "jest",
|
|
13
|
+
"clean": "rimraf dist coverage .turbo node_modules"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/bosonprotocol/core-components.git"
|
|
18
|
+
},
|
|
19
|
+
"author": "Boson Protocol",
|
|
20
|
+
"license": "Apache-2.0",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/bosonprotocol/core-components/issues"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/bosonprotocol/core-components/tree/main/packages/contracts-sdk#readme",
|
|
25
|
+
"files": [
|
|
26
|
+
"dist/*"
|
|
27
|
+
],
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "restricted"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@bosonprotocol/common": "1.1.0-alpha.0",
|
|
33
|
+
"@ethersproject/abi": "^5.5.0",
|
|
34
|
+
"@ethersproject/address": "^5.5.0",
|
|
35
|
+
"@ethersproject/bignumber": "^5.5.0",
|
|
36
|
+
"@ethersproject/constants": "^5.5.0",
|
|
37
|
+
"@ethersproject/units": "^5.5.0",
|
|
38
|
+
"cross-fetch": "^3.1.5"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"eslint": "^8.10.0",
|
|
42
|
+
"jest": "^27.5.1",
|
|
43
|
+
"nock": "^13.2.4",
|
|
44
|
+
"rimraf": "^3.0.2",
|
|
45
|
+
"ts-jest": "^27.1.3",
|
|
46
|
+
"typescript": "^4.5.5"
|
|
47
|
+
},
|
|
48
|
+
"gitHead": "fd2a2e08412acabddbaf1d4ae400bee81fdb46ab"
|
|
49
|
+
}
|