@bosonprotocol/core-sdk 1.6.0-alpha.3 → 1.6.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/dist/cjs/accounts/subgraph.d.ts +5 -9
  2. package/dist/cjs/accounts/subgraph.d.ts.map +1 -1
  3. package/dist/cjs/accounts/subgraph.js +8 -56
  4. package/dist/cjs/accounts/subgraph.js.map +1 -1
  5. package/dist/cjs/accounts/types.d.ts +0 -10
  6. package/dist/cjs/accounts/types.d.ts.map +1 -1
  7. package/dist/cjs/core-sdk.d.ts +7 -8
  8. package/dist/cjs/core-sdk.d.ts.map +1 -1
  9. package/dist/cjs/core-sdk.js +1 -1
  10. package/dist/cjs/core-sdk.js.map +1 -1
  11. package/dist/cjs/funds/index.d.ts +0 -1
  12. package/dist/cjs/funds/index.d.ts.map +1 -1
  13. package/dist/cjs/funds/index.js +0 -4
  14. package/dist/cjs/funds/index.js.map +1 -1
  15. package/dist/cjs/funds/subgraph.d.ts +2 -4
  16. package/dist/cjs/funds/subgraph.d.ts.map +1 -1
  17. package/dist/cjs/funds/subgraph.js +6 -26
  18. package/dist/cjs/funds/subgraph.js.map +1 -1
  19. package/dist/cjs/index.d.ts +1 -0
  20. package/dist/cjs/index.d.ts.map +1 -1
  21. package/dist/cjs/index.js +2 -1
  22. package/dist/cjs/index.js.map +1 -1
  23. package/dist/cjs/offers/subgraph.d.ts +7 -8
  24. package/dist/cjs/offers/subgraph.d.ts.map +1 -1
  25. package/dist/cjs/offers/subgraph.js +14 -95
  26. package/dist/cjs/offers/subgraph.js.map +1 -1
  27. package/dist/cjs/offers/types.d.ts +0 -50
  28. package/dist/cjs/offers/types.d.ts.map +1 -1
  29. package/dist/cjs/subgraph.d.ts +2510 -0
  30. package/dist/cjs/subgraph.d.ts.map +1 -0
  31. package/dist/cjs/subgraph.js +360 -0
  32. package/dist/cjs/subgraph.js.map +1 -0
  33. package/dist/cjs/utils/graphql.d.ts +28 -0
  34. package/dist/cjs/utils/graphql.d.ts.map +1 -0
  35. package/dist/cjs/utils/graphql.js +11 -0
  36. package/dist/cjs/utils/graphql.js.map +1 -0
  37. package/dist/esm/accounts/subgraph.d.ts +5 -9
  38. package/dist/esm/accounts/subgraph.d.ts.map +1 -1
  39. package/dist/esm/accounts/subgraph.js +7 -55
  40. package/dist/esm/accounts/subgraph.js.map +1 -1
  41. package/dist/esm/accounts/types.d.ts +0 -10
  42. package/dist/esm/accounts/types.d.ts.map +1 -1
  43. package/dist/esm/core-sdk.d.ts +7 -8
  44. package/dist/esm/core-sdk.d.ts.map +1 -1
  45. package/dist/esm/core-sdk.js +1 -1
  46. package/dist/esm/core-sdk.js.map +1 -1
  47. package/dist/esm/funds/index.d.ts +0 -1
  48. package/dist/esm/funds/index.d.ts.map +1 -1
  49. package/dist/esm/funds/index.js +0 -1
  50. package/dist/esm/funds/index.js.map +1 -1
  51. package/dist/esm/funds/subgraph.d.ts +2 -4
  52. package/dist/esm/funds/subgraph.d.ts.map +1 -1
  53. package/dist/esm/funds/subgraph.js +5 -25
  54. package/dist/esm/funds/subgraph.js.map +1 -1
  55. package/dist/esm/index.d.ts +1 -0
  56. package/dist/esm/index.d.ts.map +1 -1
  57. package/dist/esm/index.js +1 -0
  58. package/dist/esm/index.js.map +1 -1
  59. package/dist/esm/offers/subgraph.d.ts +7 -8
  60. package/dist/esm/offers/subgraph.d.ts.map +1 -1
  61. package/dist/esm/offers/subgraph.js +12 -100
  62. package/dist/esm/offers/subgraph.js.map +1 -1
  63. package/dist/esm/offers/types.d.ts +0 -50
  64. package/dist/esm/offers/types.d.ts.map +1 -1
  65. package/dist/esm/subgraph.d.ts +2510 -0
  66. package/dist/esm/subgraph.d.ts.map +1 -0
  67. package/dist/esm/subgraph.js +353 -0
  68. package/dist/esm/subgraph.js.map +1 -0
  69. package/dist/esm/utils/graphql.d.ts +28 -0
  70. package/dist/esm/utils/graphql.d.ts.map +1 -0
  71. package/dist/esm/utils/graphql.js +7 -0
  72. package/dist/esm/utils/graphql.js.map +1 -0
  73. package/package.json +7 -4
  74. package/src/accounts/queries.graphql +35 -0
  75. package/src/accounts/subgraph.ts +12 -70
  76. package/src/accounts/types.ts +0 -12
  77. package/src/core-sdk.ts +9 -8
  78. package/src/funds/index.ts +0 -1
  79. package/src/funds/queries.graphql +17 -0
  80. package/src/funds/subgraph.ts +8 -31
  81. package/src/index.ts +1 -0
  82. package/src/offers/queries.graphql +75 -0
  83. package/src/offers/subgraph.ts +26 -113
  84. package/src/offers/types.ts +0 -51
  85. package/src/subgraph.ts +2876 -0
  86. package/src/utils/graphql.ts +7 -0
  87. package/dist/cjs/funds/types.d.ts +0 -12
  88. package/dist/cjs/funds/types.d.ts.map +0 -1
  89. package/dist/cjs/funds/types.js +0 -3
  90. package/dist/cjs/funds/types.js.map +0 -1
  91. package/dist/cjs/utils/errors.d.ts +0 -10
  92. package/dist/cjs/utils/errors.d.ts.map +0 -1
  93. package/dist/cjs/utils/errors.js +0 -12
  94. package/dist/cjs/utils/errors.js.map +0 -1
  95. package/dist/cjs/utils/subgraph.d.ts +0 -8
  96. package/dist/cjs/utils/subgraph.d.ts.map +0 -1
  97. package/dist/cjs/utils/subgraph.js +0 -46
  98. package/dist/cjs/utils/subgraph.js.map +0 -1
  99. package/dist/esm/funds/types.d.ts +0 -12
  100. package/dist/esm/funds/types.d.ts.map +0 -1
  101. package/dist/esm/funds/types.js +0 -2
  102. package/dist/esm/funds/types.js.map +0 -1
  103. package/dist/esm/utils/errors.d.ts +0 -10
  104. package/dist/esm/utils/errors.d.ts.map +0 -1
  105. package/dist/esm/utils/errors.js +0 -10
  106. package/dist/esm/utils/errors.js.map +0 -1
  107. package/dist/esm/utils/subgraph.d.ts +0 -8
  108. package/dist/esm/utils/subgraph.d.ts.map +0 -1
  109. package/dist/esm/utils/subgraph.js +0 -28
  110. package/dist/esm/utils/subgraph.js.map +0 -1
  111. package/src/funds/types.ts +0 -11
  112. package/src/utils/errors.ts +0 -14
  113. package/src/utils/subgraph.ts +0 -43
@@ -0,0 +1,28 @@
1
+ export declare function getSubgraphSdk(subgraphUrl: string): {
2
+ getSellerByOperatorQuery(variables: import("../subgraph").Exact<{
3
+ operator: string;
4
+ fundsTokenAddress?: string;
5
+ }>, requestHeaders?: Record<string, string> | import("graphql-request/dist/types.dom").Headers | string[][]): Promise<import("../subgraph").GetSellerByOperatorQueryQuery>;
6
+ getSellerByAdminQuery(variables: import("../subgraph").Exact<{
7
+ admin: string;
8
+ fundsTokenAddress?: string;
9
+ }>, requestHeaders?: Record<string, string> | import("graphql-request/dist/types.dom").Headers | string[][]): Promise<import("../subgraph").GetSellerByAdminQueryQuery>;
10
+ getSellerByClerkQuery(variables: import("../subgraph").Exact<{
11
+ clerk: string;
12
+ fundsTokenAddress?: string;
13
+ }>, requestHeaders?: Record<string, string> | import("graphql-request/dist/types.dom").Headers | string[][]): Promise<import("../subgraph").GetSellerByClerkQueryQuery>;
14
+ getFundsByAccountIdQuery(variables: import("../subgraph").Exact<{
15
+ accountId: string;
16
+ }>, requestHeaders?: Record<string, string> | import("graphql-request/dist/types.dom").Headers | string[][]): Promise<import("../subgraph").GetFundsByAccountIdQueryQuery>;
17
+ getOfferByIdQuery(variables: import("../subgraph").Exact<{
18
+ offerId: string;
19
+ }>, requestHeaders?: Record<string, string> | import("graphql-request/dist/types.dom").Headers | string[][]): Promise<import("../subgraph").GetOfferByIdQueryQuery>;
20
+ getAllOffersOfOperatorQuery(variables: import("../subgraph").Exact<{
21
+ operator: string;
22
+ first?: number;
23
+ skip?: number;
24
+ orderBy?: import("../subgraph").Offer_OrderBy;
25
+ orderDirection?: import("../subgraph").OrderDirection;
26
+ }>, requestHeaders?: Record<string, string> | import("graphql-request/dist/types.dom").Headers | string[][]): Promise<import("../subgraph").GetAllOffersOfOperatorQueryQuery>;
27
+ };
28
+ //# sourceMappingURL=graphql.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../../src/utils/graphql.ts"],"names":[],"mappings":"AAGA,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;EAGjD"}
@@ -0,0 +1,7 @@
1
+ import { GraphQLClient } from "graphql-request";
2
+ import { getSdk } from "../subgraph";
3
+ export function getSubgraphSdk(subgraphUrl) {
4
+ const client = new GraphQLClient(subgraphUrl);
5
+ return getSdk(client);
6
+ }
7
+ //# sourceMappingURL=graphql.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphql.js","sourceRoot":"","sources":["../../../src/utils/graphql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,UAAU,cAAc,CAAC,WAAmB;IAChD,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,WAAW,CAAC,CAAC;IAC9C,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC;AACxB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bosonprotocol/core-sdk",
3
- "version": "1.6.0-alpha.3",
3
+ "version": "1.6.0-alpha.4",
4
4
  "description": "> TODO: description",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -8,6 +8,7 @@
8
8
  "scripts": {
9
9
  "dev": "tsc --watch --preserveWatchOutput ",
10
10
  "lint": "eslint --ignore-path ../../.gitignore --ext .js,.ts .",
11
+ "lint:fix": "npm run lint -- --fix",
11
12
  "build": "rimraf dist && tsc && tsc --build tsconfig.cjs.json",
12
13
  "test": "jest",
13
14
  "clean": "rimraf dist coverage .turbo node_modules"
@@ -30,13 +31,15 @@
30
31
  "access": "restricted"
31
32
  },
32
33
  "dependencies": {
33
- "@bosonprotocol/common": "^1.6.0-alpha.3",
34
+ "@bosonprotocol/common": "^1.6.0-alpha.4",
34
35
  "@ethersproject/abi": "^5.5.0",
35
36
  "@ethersproject/address": "^5.5.0",
36
37
  "@ethersproject/bignumber": "^5.5.0",
37
38
  "@ethersproject/constants": "^5.5.0",
38
39
  "@ethersproject/units": "^5.5.0",
39
- "cross-fetch": "^3.1.5"
40
+ "cross-fetch": "^3.1.5",
41
+ "graphql": "^16.5.0",
42
+ "graphql-request": "^4.3.0"
40
43
  },
41
44
  "devDependencies": {
42
45
  "eslint": "^8.10.0",
@@ -46,5 +49,5 @@
46
49
  "ts-jest": "^27.1.3",
47
50
  "typescript": "^4.5.5"
48
51
  },
49
- "gitHead": "013bc427d0c100cdaa6c55631440f7b83d720726"
52
+ "gitHead": "1c0b75626796800f55c0a0d8f178ea7e17f5e678"
50
53
  }
@@ -0,0 +1,35 @@
1
+ query getSellerByOperatorQuery($operator: Bytes!, $fundsTokenAddress: Bytes) {
2
+ sellers(where: { operator: $operator }) {
3
+ ...SellerFields
4
+ }
5
+ }
6
+
7
+ query getSellerByAdminQuery($admin: Bytes!, $fundsTokenAddress: Bytes) {
8
+ sellers(where: { admin: $admin }) {
9
+ ...SellerFields
10
+ }
11
+ }
12
+
13
+ query getSellerByClerkQuery($clerk: Bytes!, $fundsTokenAddress: Bytes) {
14
+ sellers(where: { clerk: $clerk }) {
15
+ ...SellerFields
16
+ }
17
+ }
18
+
19
+ fragment SellerFields on Seller {
20
+ id
21
+ operator
22
+ admin
23
+ clerk
24
+ treasury
25
+ active
26
+ funds(where: { tokenAddress: $fundsTokenAddress }) {
27
+ availableAmount
28
+ token {
29
+ address
30
+ decimals
31
+ name
32
+ symbol
33
+ }
34
+ }
35
+ }
@@ -1,47 +1,13 @@
1
- import { fetchSubgraph } from "../utils/subgraph";
2
- import { RawSellerFromSubgraph } from "./types";
3
-
4
- export const sellerFieldsFragment = `
5
- fragment sellerFields on Seller {
6
- id
7
- operator
8
- admin
9
- clerk
10
- treasury
11
- active
12
- funds(where: {
13
- tokenAddress: $fundsTokenAddress
14
- }) {
15
- availableAmount
16
- token {
17
- address
18
- decimals
19
- name
20
- symbol
21
- }
22
- }
23
- }
24
- `;
25
-
26
- export const getSellerByOperatorQuery = `
27
- query GetSellersByOperator($operator: String!, $fundsTokenAddress: String) {
28
- sellers(where: {
29
- operator: $operator
30
- }) {
31
- ...sellerFields
32
- }
33
- }
34
- ${sellerFieldsFragment}
35
- `;
1
+ import { getSubgraphSdk } from "../utils/graphql";
2
+ import { SellerFieldsFragment } from "../subgraph";
36
3
 
37
4
  export async function getSellerByOperator(
38
5
  subgraphUrl: string,
39
6
  operatorAddress: string,
40
7
  fundsTokenAddress?: string
41
- ): Promise<RawSellerFromSubgraph> {
42
- const { sellers = [] } = await fetchSubgraph<{
43
- sellers: RawSellerFromSubgraph[];
44
- }>(subgraphUrl, getSellerByOperatorQuery, {
8
+ ): Promise<SellerFieldsFragment> {
9
+ const sdk = getSubgraphSdk(subgraphUrl);
10
+ const { sellers = [] } = await sdk.getSellerByOperatorQuery({
45
11
  operator: operatorAddress,
46
12
  fundsTokenAddress
47
13
  });
@@ -49,25 +15,13 @@ export async function getSellerByOperator(
49
15
  return sellers[0];
50
16
  }
51
17
 
52
- export const getSellerByAdminQuery = `
53
- query GetSellersByAdmin($admin: String!, $fundsToken: String) {
54
- sellers(where: {
55
- admin: $admin
56
- }) {
57
- ...sellerFields
58
- }
59
- }
60
- ${sellerFieldsFragment}
61
- `;
62
-
63
18
  export async function getSellerByAdmin(
64
19
  subgraphUrl: string,
65
20
  adminAddress: string,
66
21
  fundsTokenAddress?: string
67
- ): Promise<RawSellerFromSubgraph> {
68
- const { sellers = [] } = await fetchSubgraph<{
69
- sellers: RawSellerFromSubgraph[];
70
- }>(subgraphUrl, getSellerByAdminQuery, {
22
+ ): Promise<SellerFieldsFragment> {
23
+ const sdk = getSubgraphSdk(subgraphUrl);
24
+ const { sellers = [] } = await sdk.getSellerByAdminQuery({
71
25
  admin: adminAddress,
72
26
  fundsTokenAddress
73
27
  });
@@ -75,25 +29,13 @@ export async function getSellerByAdmin(
75
29
  return sellers[0];
76
30
  }
77
31
 
78
- export const getSellerByClerkQuery = `
79
- query GetSellersByOperator($clerk: String!, $fundsToken: String) {
80
- sellers(where: {
81
- clerk: $clerk
82
- }) {
83
- ...sellerFields
84
- }
85
- }
86
- ${sellerFieldsFragment}
87
- `;
88
-
89
32
  export async function getSellerByClerk(
90
33
  subgraphUrl: string,
91
34
  clerkAddress: string,
92
35
  fundsTokenAddress?: string
93
- ): Promise<RawSellerFromSubgraph> {
94
- const { sellers = [] } = await fetchSubgraph<{
95
- sellers: RawSellerFromSubgraph[];
96
- }>(subgraphUrl, getSellerByClerkQuery, {
36
+ ): Promise<SellerFieldsFragment> {
37
+ const sdk = getSubgraphSdk(subgraphUrl);
38
+ const { sellers = [] } = await sdk.getSellerByClerkQuery({
97
39
  clerk: clerkAddress,
98
40
  fundsTokenAddress
99
41
  });
@@ -105,7 +47,7 @@ export async function getSellerByAddress(
105
47
  subgraphUrl: string,
106
48
  address: string,
107
49
  fundsTokenAddress?: string
108
- ): Promise<RawSellerFromSubgraph> {
50
+ ): Promise<SellerFieldsFragment> {
109
51
  const [operator, admin, clerk] = await Promise.all([
110
52
  getSellerByOperator(subgraphUrl, address, fundsTokenAddress),
111
53
  getSellerByAdmin(subgraphUrl, address, fundsTokenAddress),
@@ -1,13 +1 @@
1
- import { RawFundsEntityFromSubgraph } from "../funds/types";
2
-
3
1
  export { CreateSellerArgs } from "@bosonprotocol/common";
4
-
5
- export type RawSellerFromSubgraph = {
6
- id: string;
7
- operator: string;
8
- admin: string;
9
- clerk: string;
10
- treasury: string;
11
- active: boolean;
12
- funds: Omit<RawFundsEntityFromSubgraph, "id" | "accountId">[];
13
- };
package/src/core-sdk.ts CHANGED
@@ -15,8 +15,9 @@ import * as offers from "./offers";
15
15
  import * as orchestration from "./orchestration";
16
16
  import * as erc20 from "./erc20";
17
17
  import * as funds from "./funds";
18
+ import * as subgraph from "./subgraph";
19
+
18
20
  import { getValueFromLogs } from "./utils/logs";
19
- import { MultiQueryOpts } from "./utils/subgraph";
20
21
 
21
22
  export class CoreSDK {
22
23
  private _web3Lib: Web3LibAdapter;
@@ -80,7 +81,7 @@ export class CoreSDK {
80
81
  public async getSellerByOperator(
81
82
  operator: string,
82
83
  fundsTokenAddress?: string
83
- ): Promise<accounts.RawSellerFromSubgraph> {
84
+ ): Promise<subgraph.SellerFieldsFragment> {
84
85
  return accounts.subgraph.getSellerByOperator(
85
86
  this._subgraphUrl,
86
87
  operator,
@@ -91,7 +92,7 @@ export class CoreSDK {
91
92
  public async getSellerByClerk(
92
93
  clerk: string,
93
94
  fundsTokenAddress?: string
94
- ): Promise<accounts.RawSellerFromSubgraph> {
95
+ ): Promise<subgraph.SellerFieldsFragment> {
95
96
  return accounts.subgraph.getSellerByClerk(
96
97
  this._subgraphUrl,
97
98
  clerk,
@@ -102,7 +103,7 @@ export class CoreSDK {
102
103
  public async getSellerByAddress(
103
104
  address: string,
104
105
  fundsTokenAddress?: string
105
- ): Promise<accounts.RawSellerFromSubgraph> {
106
+ ): Promise<subgraph.SellerFieldsFragment> {
106
107
  return accounts.subgraph.getSellerByAddress(
107
108
  this._subgraphUrl,
108
109
  address,
@@ -177,7 +178,7 @@ export class CoreSDK {
177
178
 
178
179
  public async getOfferById(
179
180
  offerId: BigNumberish
180
- ): Promise<offers.RawOfferFromSubgraph> {
181
+ ): Promise<subgraph.OfferFieldsFragment> {
181
182
  return offers.subgraph.getOfferById(this._subgraphUrl, offerId);
182
183
  }
183
184
 
@@ -186,8 +187,8 @@ export class CoreSDK {
186
187
  operatorAddress: string;
187
188
  // TODO: add support for sellerId, adminAddress, clerkAddress, treasuryAddress
188
189
  },
189
- opts: MultiQueryOpts = {}
190
- ): Promise<offers.RawOfferFromSubgraph[]> {
190
+ opts?: offers.subgraph.MultiQueryOpts
191
+ ): Promise<subgraph.OfferFieldsFragment[]> {
191
192
  if (sellerFilter.operatorAddress) {
192
193
  return offers.subgraph.getAllOffersOfOperator(
193
194
  this._subgraphUrl,
@@ -286,7 +287,7 @@ export class CoreSDK {
286
287
 
287
288
  public async getFundsByAccountId(
288
289
  accountId: BigNumberish
289
- ): Promise<funds.RawFundsEntityFromSubgraph[]> {
290
+ ): Promise<subgraph.FundsEntityFieldsFragment[]> {
290
291
  return funds.subgraph.getFundsByAccountId(this._subgraphUrl, accountId);
291
292
  }
292
293
  }
@@ -1,4 +1,3 @@
1
1
  export * as iface from "./interface";
2
2
  export * as subgraph from "./subgraph";
3
3
  export * as handler from "./handler";
4
- export * from "./types";
@@ -0,0 +1,17 @@
1
+ query getFundsByAccountIdQuery($accountId: BigInt!) {
2
+ fundsEntities(where: { accountId: $accountId }) {
3
+ ...FundsEntityFields
4
+ }
5
+ }
6
+
7
+ fragment FundsEntityFields on FundsEntity {
8
+ id
9
+ availableAmount
10
+ token {
11
+ address
12
+ name
13
+ symbol
14
+ decimals
15
+ }
16
+ accountId
17
+ }
@@ -1,39 +1,16 @@
1
1
  import { BigNumberish } from "@ethersproject/bignumber";
2
- import { fetchSubgraph } from "../utils/subgraph";
3
- import { RawFundsEntityFromSubgraph } from "./types";
4
-
5
- export const fundsEntityFieldsFragment = `
6
- fragment fundsEntityFields on FundsEntity {
7
- id
8
- availableAmount
9
- token {
10
- address
11
- name
12
- symbol
13
- decimals
14
- }
15
- accountId
16
- }
17
- `;
18
-
19
- export const getFundsByAccountIdQuery = `
20
- query GetFundsByAccountIdQuery($accountId: String!) {
21
- fundsEntities(where: {
22
- accountId: $accountId
23
- }) {
24
- ...fundsEntityFields
25
- }
26
- }
27
- ${fundsEntityFieldsFragment}
28
- `;
2
+ import { getSubgraphSdk } from "../utils/graphql";
3
+ import { FundsEntityFieldsFragment } from "../subgraph";
29
4
 
30
5
  export async function getFundsByAccountId(
31
6
  subgraphUrl: string,
32
7
  accountId: BigNumberish
33
- ): Promise<RawFundsEntityFromSubgraph[]> {
34
- const { fundsEntities = [] } = await fetchSubgraph<{
35
- fundsEntities: RawFundsEntityFromSubgraph[];
36
- }>(subgraphUrl, getFundsByAccountIdQuery, { accountId });
8
+ ): Promise<FundsEntityFieldsFragment[]> {
9
+ const subgraphSdk = getSubgraphSdk(subgraphUrl);
10
+
11
+ const { fundsEntities = [] } = await subgraphSdk.getFundsByAccountIdQuery({
12
+ accountId: accountId.toString()
13
+ });
37
14
 
38
15
  return fundsEntities;
39
16
  }
package/src/index.ts CHANGED
@@ -6,6 +6,7 @@ export * as exchanges from "./exchanges";
6
6
  export * as orchestration from "./orchestration";
7
7
  export * as erc20 from "./erc20";
8
8
  export * as funds from "./funds";
9
+ export * as subgraph from "./subgraph";
9
10
 
10
11
  export { defaultConfigs, getDefaultConfig } from "@bosonprotocol/common";
11
12
 
@@ -0,0 +1,75 @@
1
+ query getOfferByIdQuery($offerId: ID!) {
2
+ offer(id: $offerId) {
3
+ ...OfferFields
4
+ }
5
+ }
6
+
7
+ query getAllOffersOfOperatorQuery(
8
+ $operator: Bytes!
9
+ $first: Int
10
+ $skip: Int
11
+ $orderBy: Offer_orderBy
12
+ $orderDirection: OrderDirection
13
+ ) {
14
+ sellers(where: { operator: $operator }) {
15
+ offers(
16
+ first: $first
17
+ skip: $skip
18
+ orderBy: $orderBy
19
+ orderDirection: $orderDirection
20
+ ) {
21
+ ...OfferFields
22
+ }
23
+ }
24
+ }
25
+
26
+ fragment OfferFields on Offer {
27
+ id
28
+ createdAt
29
+ price
30
+ sellerDeposit
31
+ protocolFee
32
+ buyerCancelPenalty
33
+ quantityAvailable
34
+ quantityInitial
35
+ validFromDate
36
+ validUntilDate
37
+ voucherRedeemableFromDate
38
+ voucherRedeemableUntilDate
39
+ fulfillmentPeriodDuration
40
+ voucherValidDuration
41
+ resolutionPeriodDuration
42
+ metadataUri
43
+ offerChecksum
44
+ voidedAt
45
+ disputeResolverId
46
+ seller {
47
+ id
48
+ operator
49
+ admin
50
+ clerk
51
+ treasury
52
+ active
53
+ }
54
+ exchangeToken {
55
+ address
56
+ decimals
57
+ name
58
+ symbol
59
+ }
60
+ metadata {
61
+ name
62
+ description
63
+ externalUrl
64
+ schemaUrl
65
+ type
66
+ }
67
+ exchanges {
68
+ id
69
+ committedDate
70
+ redeemedDate
71
+ finalizedDate
72
+ expired
73
+ disputed
74
+ }
75
+ }
@@ -1,130 +1,43 @@
1
1
  import { BigNumberish } from "@ethersproject/bignumber";
2
- import { fetchSubgraph, MultiQueryOpts } from "../utils/subgraph";
3
- import { RawOfferFromSubgraph } from "./types";
4
-
5
- export const exchangeFieldsFragment = `
6
- fragment exchangeFields on Exchange {
7
- id
8
- committedDate
9
- redeemedDate
10
- finalizedDate
11
- expired
12
- disputed
13
- }
14
- `;
15
-
16
- export const offerFieldsFragment = `
17
- fragment offerFields on Offer {
18
- id
19
- createdAt
20
- price
21
- sellerDeposit
22
- protocolFee
23
- buyerCancelPenalty
24
- quantityAvailable
25
- quantityInitial
26
- validFromDate
27
- validUntilDate
28
- voucherRedeemableFromDate
29
- voucherRedeemableUntilDate
30
- fulfillmentPeriodDuration
31
- voucherValidDuration
32
- resolutionPeriodDuration
33
- metadataUri
34
- offerChecksum
35
- voidedAt
36
- disputeResolverId
37
- seller {
38
- id
39
- operator
40
- admin
41
- clerk
42
- treasury
43
- active
44
- }
45
- exchangeToken {
46
- address
47
- decimals
48
- name
49
- symbol
50
- }
51
- metadata {
52
- name
53
- description
54
- externalUrl
55
- schemaUrl
56
- type
57
- }
58
- exchanges {
59
- ...exchangeFields
60
- }
61
- }
62
- ${exchangeFieldsFragment}
63
- `;
64
-
65
- export const getOfferByIdQuery = `
66
- query GetOfferById($offerId: ID!) {
67
- offer(id: $offerId) {
68
- ...offerFields
69
- }
70
- }
71
- ${offerFieldsFragment}
72
- `;
2
+ import { getSubgraphSdk } from "../utils/graphql";
3
+ import {
4
+ OfferFieldsFragment,
5
+ OrderDirection,
6
+ Offer_OrderBy
7
+ } from "../subgraph";
8
+
9
+ export type MultiQueryOpts = {
10
+ orderBy: Offer_OrderBy;
11
+ orderDirection: OrderDirection;
12
+ };
73
13
 
74
14
  export async function getOfferById(
75
15
  subgraphUrl: string,
76
16
  offerId: BigNumberish
77
- ): Promise<RawOfferFromSubgraph> {
78
- const { offer } = await fetchSubgraph<{ offer: RawOfferFromSubgraph }>(
79
- subgraphUrl,
80
- getOfferByIdQuery,
81
- { offerId: offerId.toString() }
82
- );
17
+ ): Promise<OfferFieldsFragment> {
18
+ const subgraphSdk = getSubgraphSdk(subgraphUrl);
83
19
 
84
- return offer;
85
- }
20
+ const { offer } = await subgraphSdk.getOfferByIdQuery({
21
+ offerId: offerId.toString()
22
+ });
86
23
 
87
- export const getAllOffersOfOperatorQuery = `
88
- query GetAllOffersOfOperatorQuery(
89
- $operator: String!,
90
- $first: Int,
91
- $skip: Int,
92
- $orderBy: String,
93
- $orderDirection: String
94
- ) {
95
- sellers(where: {
96
- operator: $operator
97
- }) {
98
- offers(
99
- first: $first
100
- skip: $skip
101
- orderBy: $orderBy
102
- orderDirection: $orderDirection
103
- ) {
104
- ...offerFields
105
- }
106
- }
24
+ return offer;
107
25
  }
108
- ${offerFieldsFragment}
109
- `;
110
26
 
111
27
  export async function getAllOffersOfOperator(
112
28
  subgraphUrl: string,
113
29
  operatorAddress: string,
114
- opts: MultiQueryOpts = {}
115
- ): Promise<RawOfferFromSubgraph[]> {
116
- const { sellers } = await fetchSubgraph<{
117
- sellers: { offers: RawOfferFromSubgraph[] };
118
- }>(subgraphUrl, getAllOffersOfOperatorQuery, {
119
- operator: operatorAddress.toLowerCase(),
120
- first: 100,
121
- skip: 0,
122
- orderBy: "createdAt",
123
- orderDirection: "desc",
124
- ...opts
30
+ opts?: MultiQueryOpts
31
+ ): Promise<OfferFieldsFragment[]> {
32
+ const subgraphSdk = getSubgraphSdk(subgraphUrl);
33
+
34
+ const { sellers = [] } = await subgraphSdk.getAllOffersOfOperatorQuery({
35
+ operator: operatorAddress,
36
+ orderBy: opts?.orderBy,
37
+ orderDirection: opts?.orderDirection
125
38
  });
126
39
 
127
- if (!sellers) {
40
+ if (!sellers || sellers.length === 0) {
128
41
  return [];
129
42
  }
130
43
 
@@ -1,52 +1 @@
1
1
  export { CreateOfferArgs } from "@bosonprotocol/common";
2
-
3
- export type RawOfferFromSubgraph = {
4
- id: string;
5
- createdAt: string;
6
- price: string;
7
- sellerDeposit: string;
8
- protocolFee: string;
9
- buyerCancelPenalty: string;
10
- quantityAvailable: string;
11
- quantityInitial: string;
12
- validFromDate: string;
13
- validUntilDate: string;
14
- voucherRedeemableFromDate: string;
15
- voucherRedeemableUntilDate: string;
16
- fulfillmentPeriodDuration: string;
17
- voucherValidDuration: string;
18
- resolutionPeriodDuration: string;
19
- metadataUri: string;
20
- offerChecksum: string;
21
- voidedAt: null | string;
22
- disputeResolverId: string;
23
- seller: {
24
- id: string;
25
- operator: string;
26
- admin: string;
27
- clerk: string;
28
- treasury: string;
29
- active: boolean;
30
- };
31
- exchangeToken: {
32
- address: string;
33
- decimals: string;
34
- name: string;
35
- symbol: string;
36
- };
37
- metadata: null | {
38
- name: string;
39
- description: string;
40
- externalUrl: string;
41
- schemaUrl: string;
42
- type: string;
43
- };
44
- exchanges: {
45
- id: string;
46
- committedDate: string;
47
- disputed: boolean;
48
- expired: boolean;
49
- finalizedDate: string;
50
- redeemedDate: string;
51
- }[];
52
- };