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